枚举每一列的位置,求哪个字符出现的次数最多
#include<iostream>
#include<string>
#include<map>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<assert.h>
#include<cstring>
using namespace std;
#define _for(i, a, b) for (int i = (a); i < (b); ++i)
#define _rep(i, a, b) for (int i = (a); i <= (b); ++i)
char s[60][1050];
map<int, char> mp;
int main(){
mp[0] = ‘A‘;
mp[1] = ‘C‘;
mp[2] = ‘G‘;
mp[3] = ‘T‘;
int T;
cin >> T;
while(T--){
int n, m,cnt=0;
cin >> n >> m;
_for(i,0,n){
scanf("%s", s[i]);
}
string ans = "";
_for(i,0,m){
int a[4] = {0};
_for(j,0,n){
switch(s[j][i]){
case ‘A‘:
a[0]++;
break;
case ‘C‘:
a[1]++;
break;
case ‘G‘:
a[2]++;
break;
case ‘T‘:
a[3]++;
break;
}
}
int index = 0, num = a[0];
_for(i, 1, 4)
{
if (a[i] > num)
{
num = a[i];
index = i;
}
}
cnt += (n - num);
ans.append(1, mp[index]);
}
cout << ans << endl;
cout << cnt << endl;
}
return 0;
}
原文地址:https://www.cnblogs.com/zlwjy/p/11563935.html