UVa1368

来源:互联网 发布:屏蔽一段ip的js代码 编辑:程序博客网 时间:2024/06/08 09:49

/*

这道题最大的经验就是要注意审题和理解题意,‘注意结合样例理解

一开始以为最后的答案是在输入DNA序列中进行寻找,走了很多弯路。

*/
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<vector>
#include<utility>
#include<unordered_set>
#include<unordered_map>
#include<string.h>
using namespace std;
const int nmax=1000+10;
char s[nmax];
int cnt[nmax][4];
unordered_map<char,int>mm={{'A',0},{'C',1},{'G',2},{'T',3}};
char mn[]={'A','C','G','T'};
int main(){
    int T,m,n,pos,now,ans;
    scanf("%d",&T);
    while(T--){
        scanf("%d %d",&m,&n);
        memset(cnt,0,sizeof(cnt));
        for(int i=0;i<m;++i){
            scanf("%s",s);
            for(int j=0;j<n;++j)++cnt[j][mm[s[j]]];
        }
        ans=0;
        for(int j=0;j<n;++j){
            now=0,pos=0;
            for(int k=0;k<4;++k){
                ans+=cnt[j][k];
                if(now<cnt[j][k])pos=k,now=cnt[j][k];
            }
            s[j]=mn[pos];
            ans-=cnt[j][pos];
        }
        printf("%s\n",s);
        printf("%d\n",ans);
    }
    return 0;
}