#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
struct cell
{
char ch;
int n;
cell(char c ='-',int t=0):ch(c),n(t){}
bool operator<(const cell & cl)const{
if(n>cl.n)return true;
else if(n == cl.n && ch < cl.ch)return true;
else return false;
}
};
int ch2int(char c){
switch(c){
case 'A':
return 0;
case 'G':
return 1;
case 'C':
return 2;
case 'T':
return 3;
}
return -1;
}
int main()
{
int t;
cin>>t;
for(int k=0;k<t;k++){
int n,m;
cin>>n>>m;
string dna;
vector<string> col(m);
for(int i=0;i<m;i++){
col[i].resize(n);
}
for(int i=0;i<n;i++){
cin>>dna;
for(int j=0;j<m;j++){
col[j][i]=dna[j];
}
}
string res;
int hamming = 0;
for(int i=0;i<m;i++){
vector<cell> cnt(4);
cnt[0]=cell('A');cnt[1]=cell('G');cnt[2]=cell('C');cnt[3]=cell('T');
for(int j=0;j<n;j++){
cnt[ch2int(col[i][j])].n++;
}
sort(cnt.begin(),cnt.end());
res +=cnt[0].ch;
for(int j=0;j<n;j++){
if(res[i] != col[i][j])
hamming++;
}
}
cout<<res<<endl<<hamming<<endl;
}
return 0;
}
1368 - DNA Consensus String
最新推荐文章于 2021-03-16 22:17:30 发布