题目链接 :https://vjudge.net/problem/UVA-1368
题目首先得知道什么是Hamming距离(自行查找),然后注意出现多个解是选择字典序小者(直接将字典序排号比较),**注意数组大小。
1 #include<stdio.h> 2 #include<string.h> 3 #define maxn 1000 4 #define maxm 1000 5 6 char DNA[maxn][maxm]; 7 int main() 8 { 9 int N; 10 scanf("%d",&N); 11 while(N--) 12 { 13 int n,m,list[4],num1 = 0,num = 0; 14 scanf("%d %d",&n,&m); 15 for (int i = 0;i < n;i++) 16 scanf("%s",DNA[i]); 17 for(int i = 0;i < m;i++ ){ 18 memset(list,0,sizeof(list)); 19 for (int j = 0;j < n;j++) 20 { 21 if(DNA[j][i] == ‘A‘) 22 list[0]++; 23 else if(DNA[j][i] == ‘C‘) 24 list[1]++; 25 else if(DNA[j][i] == ‘G‘) 26 list[2]++; 27 else 28 list[3]++; 29 } 30 int tmp = 0,ans; 31 for (int k = 0;k < 4;k++) 32 { 33 if(list[k] > tmp){ 34 ans = k; 35 tmp = list[k]; 36 num1 = n - list[k]; 37 } 38 } 39 num += num1; 40 if(ans == 0) printf("A"); 41 if(ans == 1) printf("C"); 42 if(ans == 2) printf("G"); 43 if(ans == 3) printf("T"); 44 } 45 printf("\n%d\n",num); 46 } 47 48 return 0; 49 } 50
原文地址:https://www.cnblogs.com/Dicer/p/8448143.html
时间: 2024-10-07 03:58:16