DNA Consensus String
解决方法:寻找每列中出现最多的字母。
AC代码
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#include <utility>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define lep(i,l,r) for(int i=l;i>=r;i--)
#define ms(arr) memset(arr,0,sizeof(arr))
//priority_queue<int,vector<int> ,greater<int> >q;
const int maxn = (int)1e5 + 5;
const ll mod = 1e9+7;
char mapp[55][1050];
char arr[1200];
map<char,int> mt;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
//freopen("out.txt", "w", stdout);
ios::sync_with_stdio(0),cin.tie(0);
int T;
scanf("%d",&T);
while(T--)
{
int n,m;
ms(arr);
scanf("%d %d",&n,&m);
rep(i,1,n) {
scanf("%s",mapp[i]+1);
}
int ans=0;
rep(j,1,m) {
int maxl=0;
for(char t='A';t<='Z';t++)
mt[t]=0;
rep(i,1,n) {
mt[mapp[i][j]]++;
}
for(char t='A';t<='Z';t++)
{
if(mt[t]>maxl)
{
arr[j]=t;
maxl=mt[t];
}
ans+=mt[t];
}
ans-=maxl;
}
rep(j,1,m) {
printf("%c",arr[j]);
}
printf("\n");
printf("%d\n",ans);
}
return 0;
}