UVA-1368 DNA Consensus String

 1 #include <iostream>
 2 #include <stdlib.h>
 3 #include <string>
 4 #include <vector>
 5 #include <algorithm>
 6 #include <string.h>
 7 #include <stack>
 8 #include <unordered_map>
 9 #include <math.h>
10 #include <iomanip>
11 
12 using namespace std;
13 
14 int main()
15 {
16     int T;
17     cin >> T;
18     while(T --)
19     {
20         int m,n;
21         cin >> m >> n;
22         char wordList[m+3][n+3];
23 
24         for(int i = 0; i < m; i ++)
25         {
26             for(int j = 0; j < n; j ++)
27             {
28                 cin >> wordList[i][j];
29             }
30         }
31 
32         string strResult;
33         int sumResult = 0;
34         for(int i = 0; i < n; i ++)
35         {
36             int A = 0,T = 0,C = 0,G = 0;
37             for(int j = 0; j < m; j ++)
38             {
39                 if(wordList[j][i] == 'A')
40                     A ++;
41                 else if(wordList[j][i] == 'T')
42                     T ++;
43                 else if(wordList[j][i] == 'C')
44                     C ++;
45                 else if(wordList[j][i] == 'G')
46                     G ++;
47             }
48             
49             if(A>=T && A>=C && A>=G)
50             {
51                 sumResult += T+C+G;
52                 strResult += 'A';
53             }
54             else if(C>=T && C>=A && C>=G)
55             {
56                 sumResult += A+T+G;
57                 strResult += 'C';
58             }
59             else if(G>=T && G>=A && G>=C)
60             {
61                 sumResult += T+C+A;
62                 strResult += 'G';
63             }
64             else if(T>=A && T>=C && T>=G)
65             {
66                 sumResult += A+C+G;
67                 strResult += 'T';
68             }
69         }
70         cout << strResult << endl;
71         cout << sumResult << endl;
72     }
73     return 0;
74 }
原文地址:https://www.cnblogs.com/Asurudo/p/9607842.html