C语言问题:DNA排序

Python013

C语言问题:DNA排序,第1张

输入

计算逆序

稳定排序

代码:

#include <stdio.h>

#include <string.h>

typedef struct

{

char arr[51]

int v

}ARR

int main()

{

ARR list[100]

ARR t

int n,l,i,j,k

scanf("%d%d", &l, &n)

for(i = 0 i < n i ++)

{

scanf("%s", list[i].arr)

list[i].v = 0

for(j = 0 j < l - 1 j ++)

{

for(k = j + 1 k < l k ++)

if(list[i].arr[k] < list[i].arr[j])

list[i].v ++

}

}

for (i = 0 i < n i++) 

{         

for (j = n - 1 j > i j--)

{     

if (list[j].v < list[j-1].v) 

{        

memcpy(&t, &list[j-1], sizeof t)   

memcpy(&list[j-1], &list[j], sizeof t)   

memcpy(&list[j], &t, sizeof t)   

}      

}   

for(i = 0 i < n i ++)

printf("%s\n", list[i].arr)

return 0

}

供参考

是否有问题? 有问题请追问 没问题请采纳

A<->T,C<->G

进行互换就可以

#include<stdio.h>

#include<stdlib.h>

main()

{

char input[50]/*Defined to store the DNA code sequence*/

int i/*Used as counter*/

printf("\n\tInput the DNA sequence you want to convert\n\t")

gets(input)

for(i=0input[i]!='\0'i++)

{

switch(input[i])

{

case 'A':printf("T")break

case 'T':printf("A")break

case 'C':printf("G")break

case 'G':printf("C")break

default:

{

printf("An Unknown match occurs,Fail to respond")

exit(0)/*Quit the program directly*/

}

}

}

system("pause")/*As this program is made in Dev,use this expression to pause the program*/

}