DNA Consensus String UVA - 1368
阿新 • • 發佈:2018-11-06
#include <iostream> #include <string> using namespace std; int m, n; // 行數,列數 string strs[50]; // 儲存每一行 int num = 0; string result; // 儲存結果 void Counts(); int main() { int T; // 迴圈次數 cin >> T; while (T--) { cin >> m >> n; while (getchar() != '\n') continue; for (int i = 0; i < m; i++) getline(cin, strs[i]); Counts(); cout << result << endl; cout << num << endl; } return 0; } void Counts() { char c; int A = 0, C = 0, G = 0, T = 0; int max = 0; num = 0; result.clear(); for (int j = 0; j < n; j++) { for (int i = 0; i < m; i++) { if (strs[i][j] == 'A') A++; else if (strs[i][j] == 'C') C++; else if (strs[i][j] == 'G') G++; else T++; } if (A > max) { max = A; c = 'A'; } if (C > max) { max = C; c = 'C'; } if (G > max) { max = G; c = 'G'; } if (T > max) { max = T; c = 'T'; } num += m - max; result += c; A = C = G = T = max = 0; } }