UVa 1368 DNA Consensus String

来源:互联网 发布:追星的软件 编辑:程序博客网 时间:2024/06/14 08:21
#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;} 

0 0