您的位置:首页 > 其它

UVa1368 DNA Consensus String

2015-09-09 14:04 519 查看
#include <stdio.h>

char s[51][1001];

char compareA(int countA, int countC, int countG, int countT)
{
	int temp = countT;
	char c = 'T';
	if(temp <= countG) 
	{
		temp = countG;
		c = 'G';
	}
	if(temp <= countC)
	{
		temp = countC;
		c = 'C';
	}
	if(temp <= countA)
	{
		temp = countA;
		c = 'A';
	}
	return c;
}

int main()
{
	int num = 0;
	int m, n;
	scanf("%d", &num);
	while(num--)
	{
		scanf("%d %d", &m, &n);
		
		for(int i=0; i<m; i++)
        {
            scanf("%s",s[i]);
        }
        
        int countA=0, countC=0, countG=0, countT=0;
        char temp;
        int total = 0;
        int all = 0;
        for(int i = 0; i < n; i++)
        {
        	countA=0, countC=0, countG=0, countT=0;
			for(int j = 0; j < m; j++)
        	{
        		if(s[j][i] == 'A')
        		  countA++;
        		else if(s[j][i] == 'C')
        		  countC++;
        		else if(s[j][i] == 'G')
        		  countG++;
        		else if(s[j][i] == 'T')
        		  countT++;
			}
			temp = compareA(countA, countC, countG, countT);
			total = countA + countC + countG + countT;
			if(temp == 'A')
        		total -= countA;
        	else if(temp == 'C')
        		total -= countC;
        	else if(temp == 'G')
        		total -= countG;
        	else if(temp == 'T')
        		total -= countT;
        	
        	all += total;
			printf("%c", temp);
		}
		printf("\n");
		printf("%d\n", all);
	}	
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: