您的位置:首页 > 其它

DNA Consensus String UVA - 1368

2017-04-03 12:47 387 查看
问题类型:字符串,搜索。

03pie’s solution for [UVA-1368]:

#include<cstdio>
#include<iostream>
#include<sstream>
#include<cstdlib>
#include<cmath>
#include<cctype>//isalpha(),isdigit(),issprint()|toupper(),tolower()
#include<string>//strlen()
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<ctime>
#include<vector>
#include<fstream>
#include<list>
using namespace std;

#define ms(s) memset(s,0,sizeof(s))typedef unsigned long long ULL;
typedef long long LL;

const double PI = 3.141592653589;
const int INF = 0x3fffffff;

#define maxn 1000
char c(int i)
{
if(i==0) return 'A';
if(i==1) return 'C';
if(i==2) return 'G';
if(i==3) return 'T';
}

char DNAs[maxn][maxn];
int main(){
//    freopen("F://inp.txt","r",stdin);

int T;
scanf("%d",&T);
while(T--)
{
int count[4];
memset(count,0,sizeof(count));
int row,col;
scanf("%d%d",&row,&col);
char ans[col];
int anscut=0;
getchar();
for(int i=0;i<row;i++)
{
gets(DNAs[i]);
}
for(int j=0;j<col;j++)
{
for(int i=0;i<row;i++)
{
if(DNAs[i][j]=='A')         count[0]++;
else if(DNAs[i][j]=='C')    count[1]++;
else if(DNAs[i][j]=='G')    count[2]++;
else if(DNAs[i][j]=='T')    count[3]++;
}
int max=count[0],tmp=0;
for(int k=1;k<4;k++)
{
if(count[k]>max)
{
max=count[k];
tmp=k;
}
}

ans[j]=c(tmp);
anscut+=(row-max);

memset(count,0,sizeof(count));
}
for(int i=0;i<col;i++)
printf("%c",ans[i]);
printf("\n%d\n",anscut);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: