Input
Your program is to read from standard input. The input consists of T test cases. The number of test cases T is given in the first line of the input. Each test case starts with a line containing two integers m and n which are separated by a single space. The integer m (4 ≤ m ≤ 50) represents the number of DNA sequences and n (4 ≤ n ≤ 1000) represents the length of the DNA sequences, respectively. In each of the next m lines, each DNA sequence is given.
Output
Your program is to write to standard output. Print the consensus string in the first line of each case and the consensus error in the second line of each case. If there exists more than one consensus string, print the lexicographically smallest consensus string.
Sample Input
3
5 8
TATGATAC
TAAGCTAC
AAAGATCC
TGAGATAC
TAAGATGT
4 10
ACGTACGTAC
CCGTACGTAG
GCGTACGTAT
TCGTACGTAA
6 10
ATGTTACCAT
AAGTTACGAT
AACAAAGCAA
AAGTTACCTT
AAGTTACCAA
TACTTACCAA
Sample Output
TAAGATAC
7
ACGTACGTAA
6
AAGTTACCAA
12
Solution
#include<stdio.h>
#include<string.h>
int m,n,sum=0;
char a[55][1002];
char b[1002];
int c[1002][5];
const char d[]="ACGT";
int main(){
int t;
scanf("%d",&t);
while(t--){
sum=0;
memset(c,0,sizeof(c));
scanf("%d %d\n",&m,&n);
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
scanf("%c",&a[i][j]);
if(a[i][j]=='A') c[j][0]++;
else if(a[i][j]=='C') c[j][1]++;
else if(a[i][j]=='G') c[j][2]++;
else c[j][3]++;
}
getchar();
}
for(int i=0;i<n;i++){
int k,maxn=-1;
for(int j=0;j<4;j++){
if(c[i][j]>maxn){
maxn=c[i][j];
k=j;
}
}
sum+=(m-maxn);
b[i]=d[k];
}
for(int i=0;i<n;i++)
printf("%c",b[i]);
printf("\n%d\n",sum);
}
return 0;
}