《算法竞赛入门经典2ndEdition 》习题3-7 DNA序列(DNA Consensus String, Uva1368)

昨天晚上做的,做完太晚就没写,今天一大早又去上课了,现在终于有时间写了。

#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),结果过了,也就是说需要在文末也输出一个空行。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值