LA_3602
由于每一位都是独立的,我们依次处理每一位即可。对每一位找到出现次数最多的字符,如果次数相同的话,就找字典序较小的那个。
#include<stdio.h> #include<string.h> #include<iostream> #define MAXN 60 #define MAXL 1010 int N, L; char a[MAXN][MAXL], id[128], ch[4] = {'A', 'C', 'G', 'T'}; void input() { scanf("%d%d", &N, &L); for(int i = 0; i < N; i ++) scanf("%s", a[i]); } int process(int i) { int h[4] = {0}, k, n = -1; for(int j = 0; j < N; j ++) ++ h[id[a[j][i]]]; for(int j = 0; j < 4; j ++) if(h[j] > n) n = h[j], k = j; std::cout << ch[k]; return N - n; } int main() { int t; scanf("%d", &t); id['A'] = 0, id['C'] = 1, id['G'] = 2, id['T'] = 3; while(t --) { input(); int n = 0; for(int i = 0; i < L; i ++) n += process(i); std::cout << std::endl << n << std::endl; } return 0; }