int main() { int i, n, k; scanf("%d %d", &n, &k); for (i = 0; i < n; i++) scanf("%d", &coins[i]); printf("%d\n", getComb(n, k)); }
int getData (char *label, char *data){ int status, i; struct sequence *seq; status = 0; /* ** Find the sequence label. */ seq = &(seqList); while (strcmp (seq->label, label) != 0) { //printf("Label : %s|\n", label); //printf("SeqLab : %s|\n", seq->label); if (seq->next == NULL) { status = -1; fprintf (stderr, "Unmatched sequence label in tree: '%s'.\n", label); goto End_of_Routine; } seq = seq->next; } /* ** Get the data from the requested columns. */ data[0] = seq->sequence[col1-1]; data[1] = seq->sequence[col2-1]; data[2] = '\0'; /* ** Remember the observed combination. */ i = getComb (data); if (i == -1) { status = -1; fprintf (stderr, "Invalid nucleotide or amino acid combination of species %s.\n", label); goto End_of_Routine; } obsCombs[i] = 1; End_of_Routine: /* ** Return the status. */ return (status); }
int createTree1(char* treeParenth, int num_chars){ int i, index, assign, indexname, indexdistance, status; char name[128], distance[32]; struct node *current, *son; status = 0; i = 0; current = NULL; while (i< num_chars && treeParenth[i]!=';'){ if (treeParenth[i]=='(' ){ if (current == NULL){ //printf("HERE1 %d\n",i); current = &root; }else{ //printf("HERE2 %d\n",i); son = (struct node*)malloc (sizeof (struct node)); strcpy(son->data, "internal"); strcpy(son->label, "internal"); son->parent=current; son->dist=0.0;// will be changed afterwards son->right=NULL; son->left=NULL; son->probVector = (double *)malloc (nrComb * sizeof (double)); for (assign=0;assign<nrComb;assign++){ son->probVector[assign]=0.0; } insert(current,son); current=son; } i++; }else if (treeParenth[i]==',' || treeParenth[i]==')'){ //printf("HERE3 %d\n",i); if (treeParenth[i]==')'){ while (treeParenth[i]!=':' && treeParenth[i]!=',' && treeParenth[i]!=';'){ i++; } } else{ i++; } } else if (treeParenth[i]==':'){ //printf("HERE4 %d\n",i); indexdistance=0; while (treeParenth[i]!=',' && treeParenth[i]!=')' && treeParenth[i]!=';' ){ if(treeParenth[i]!= ':') { distance[indexdistance]=treeParenth[i]; indexdistance++; } i++; } distance[indexdistance]='\0'; current->dist=atof(distance); current=current->parent; }else { //printf("HERE5 %d\n",i); indexname = 0; while (treeParenth[i]!=':'){ name[indexname]=treeParenth[i]; indexname++; i++; } name[indexname]='\0'; indexdistance=0; while (treeParenth[i]!=',' && treeParenth[i]!=')' && treeParenth[i]!=';' ){ if(treeParenth[i]!= ':') { distance[indexdistance]=treeParenth[i]; indexdistance++; } i++; } distance[indexdistance]='\0'; son = (struct node*)malloc(sizeof(struct node)); strcpy (son->label, name); //printf("%s\n", name); if (getData (name, son->data) == -1) { status = -1; goto End_of_Routine; } son->parent=current; son->dist=atof(distance); son->right=NULL; son->left=NULL; index = getComb (son->data); if (index == -1) { status = -1; fprintf (stderr, "Invalid nucleotide combination in given columns.\n"); goto End_of_Routine; } son->probVector = (double *)malloc (nrComb * sizeof (double)); for (assign = 0; assign < nrComb; assign++) { son->probVector[assign] = 0.0; } son->probVector[index] = 1.0; insert(current,son); } } End_of_Routine: /* ** Return the status. */ return (status); }