您的位置:首页 > 其它

zoj3132(uva1368) DNA Consensus String(水)

2016-03-16 21:28 423 查看
水题,但感觉自己不在状态,可能是作业没做= =。没有初始化ans数组还WA了两次。。。

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <set>
#include <vector>
#include <string>
#include <sstream>
#include <ctype.h>
#include <string.h>
using namespace std;

const int N = 1111;
const int INF = 10000000;

char Map[60]
;

struct node
{
char c;
int num;
}tmp[4];

void init()
{
node tmp1, tmp2, tmp3, tmp4;
tmp[0].c = 'A';
tmp[1].c = 'C';
tmp[2].c = 'G';
tmp[3].c = 'T';
for(int i = 0; i < 4; i ++)
{
tmp[i].num = 0;
}
}

int main()
{
//  freopen("in.txt", "r", stdin);
int T, row, line;
scanf("%d", &T);
while(T --)
{
scanf("%d%d", &row, &line);
memset(Map, 0, sizeof(Map));
for(int i = 0; i < row; i ++)
scanf("%s", Map[i]);
char ans
;
memset(ans, 0, sizeof(ans));
for(int i = 0; i < line; i ++)
{
init();
for(int j = 0; j < row; j ++)
{
if(Map[j][i] == 'A') tmp[0].num ++;
else if(Map[j][i] == 'C') tmp[1].num ++;
else if(Map[j][i] == 'G') tmp[2].num ++;
else if(Map[j][i] == 'T') tmp[3].num ++;
}
int maxx = -INF, ans0;
for(int j = 0; j < 4; j ++)
{
maxx = max(maxx, tmp[j].num);
}
for(int j = 0; j < 4; j ++)
{
if(tmp[j].num == maxx)
{
ans[i] = tmp[j].c;
break;
}
}
}
int num0 = 0;
for(int i = 0; i < row; i ++)
for(int j = 0; j < line; j ++)
{
if(Map[i][j] != ans[j]) num0 ++;
}
cout << ans << endl;
printf("%d\n", num0);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  uva zoj