思路:统计字符的最大值 若有相同的以字典序第一个为准输入
简单题
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
int T, m, n;
int i, j;
int a_count = 0, g_count = 0,c_count=0,t_count=0;
char DNA[50][10001];
char output[10001];
int min;
cin >> T;
while (T--)
{
min = 0;
cin >> m >> n;
getchar();
for (i = 0; i < m; i++) //输入序列
fgets(DNA[i], n+2, stdin);
for (i = 0; i < n; i++) //统计个数
{
for (j = 0; j < m; j++)
{
switch (DNA[j][i])
{
case 'A':
a_count++;
break;
case 'G':
g_count++;
break;
case 'C':
c_count++;
break;
case 'T':
t_count++;
break;
}
}
if (a_count >= c_count&&a_count >= g_count &&a_count >= t_count)
{
output[i] = 'A';
min += (m - a_count);
}
if (c_count >= g_count &&c_count >= t_count&&c_count > a_count)
{
output[i] = 'C';
min += (m - c_count);
}
if (g_count >= t_count&&g_count > a_count&&g_count > c_count)
{
output[i] = 'G';
min += (m - g_count);
}
if (t_count > a_count&&t_count > g_count&&t_count > c_count)
{
output[i] = 'T';
min += (m - t_count);
}
a_count = 0;
g_count = 0;
c_count = 0;
t_count = 0;
}
for (i = 0; i < n; i++)
printf("%c", output[i]);
printf("\n%d\n", min);
}
return 0;
}