昨天晚上做的,做完太晚就没写,今天一大早又去上课了,现在终于有时间写了。
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int maxn = 1000;
int book[5][maxn + 10];
int main()
{
freopen("New Text Document.txt","r",stdin);
freopen("Output.txt","w",stdout);
int t, m, n;
char c;
scanf("%d", &t);
while(t--)
{
memset(book, 0, sizeof(book));
scanf("%d%d", &m, &n);
getchar();//get endl
for(int i = 0; i < m; i++)
{
for(int j = 0; j < n; j++)
{
scanf("%c", &c);
switch(c)
{
case 'A': book[0][j]++;break;
case 'C': book[1][j]++;break;
case 'G': book[2][j]++;break;
case 'T': book[3][j]++;break;
}
//printf("%c", c);
}
getchar();//get endl
}
//for(int i = 0; i < n; i++)
// {
// for(int j = 0; j < 4; j++)
// printf("%d", book[j][i]);
// printf("\n");
// }
int max, flag, cnt = 0;
for(int i = 0; i < n; i++)
{
max = 0;
for(int j = 0; j < 4; j++)
if(book[j][i] > max)
{
max = book[j][i];
flag = j;
}
cnt += m-book[flag][i];
switch(flag)
{
case 0: printf("A");break;
case 1: printf("C");break;
case 2: printf("G");break;
case 3: printf("T");break;
}
}
printf("\n%d", cnt);
//if(t)
printf("\n");
}
return 0;
}
循环的末尾,第一开始我写的是if(t) printf("\n"); ,文末未留空格,但是却WA,去掉了if(t),结果过了,也就是说需要在文末也输出一个空行。

本文分享了一段使用C++编写的编程竞赛代码,通过输入DNA序列进行统计分析,找出每列出现最多的核苷酸并计算错误率。文章详细展示了如何读取文件、处理数据以及输出结果。
1762

被折叠的 条评论
为什么被折叠?



