标签:
本题只有四个字符,用常量数组存储它们
#include <cstdio> #include <cstring> char a[100][1500]; int b[10]; int main() { int cnt, m, n, hamming= 0,maxum = 0; char c[10] ="ACGT"; scanf("%d",&cnt); while(cnt--) { scanf("%d%d",&m,&n); getchar(); for(int i = 0; i < m; i++) { for(int j = 0; j < n;j++) scanf("%c",&a[i][j]); getchar(); } for(int j = 0; j < n; j++) { memset(b,0,sizeof(b)); for(int i = 0; i < m; i++) { if(a[i][j] == ‘A‘) b[0]++; if(a[i][j] == ‘C‘) b[1]++; if(a[i][j] == ‘G‘) b[2]++; if(a[i][j] == ‘T‘) b[3]++; } for(int i = 1; i < 4; i ++) if(b[i] > b[maxum]) maxum = i; printf("%c",c[maxum]); for(int i = 0; i < 4; i ++) if(i != maxum ) hamming += b[i]; maxum = 0; } printf("\n%d\n",hamming); hamming = 0; } return 0; }
标签:
原文地址:http://www.cnblogs.com/ekinzhang/p/4300778.html