标签:style blog http color os io ar for art
最近审题老是一错再错,Orz
题目中说求一个Hamming值总和最小的字符串,而不是从所给字符中找一个最小的
这样的话,我们逐列处理,所求字符串当前位置的字符应该是该列中出现次数最多其次ASCII值最小的
代码有点挫了,if语句太多了
1 //#define LOCAL 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 using namespace std; 6 7 char gene[52][1010], ans[1010]; 8 int num[4]; 9 10 int main(void) 11 { 12 #ifdef LOCAL 13 freopen("3602in.txt", "r", stdin); 14 #endif 15 16 int T; 17 scanf("%d", &T); 18 while(T--) 19 { 20 int n, m, hamming = 0; 21 scanf("%d%d", &n ,&m); 22 for(int i = 0; i < n; ++i) 23 scanf("%s", gene[i]); 24 for(int i = 0; i < m; ++i) 25 { 26 int Max = 0; 27 for(int j = 0; j < 4; ++j) num[j] = 0; 28 for(int j = 0; j < n; ++j) 29 { 30 if(gene[j][i] == ‘A‘) ++num[0]; 31 if(gene[j][i] == ‘C‘) ++num[1]; 32 if(gene[j][i] == ‘G‘) ++num[2]; 33 if(gene[j][i] == ‘T‘) ++num[3]; 34 } 35 for(int j = 1; j < 4; ++j) 36 if(num[j] > num[Max]) 37 Max = j; 38 if(Max == 0) ans[i] = ‘A‘; 39 if(Max == 1) ans[i] = ‘C‘; 40 if(Max == 2) ans[i] = ‘G‘; 41 if(Max == 3) ans[i] = ‘T‘; 42 hamming += num[0] + num[1] + num[2] + num[3] - num[Max]; 43 } 44 ans[m] = ‘\0‘; 45 printf("%s\n%d\n", ans, hamming); 46 } 47 return 0; 48 }
标签:style blog http color os io ar for art
原文地址:http://www.cnblogs.com/AOQNRMGYXLMV/p/3942150.html