사전순이기 때문에 A, C, G, T 순으로 세로줄에 등장하는 갯수가 제일 많은 뉴클레오타이드로 배치한다.
Hamming Distance는 세로줄에서 선택된 뉴클레오타이드를 제외하고 나머지 뉴클레오타이드의 등장횟수를 세면 된다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| #include <iostream> using namespace std; int n, m, h; int main() { char c[1000][50]; cin >> n >> m; for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin >> c[i][j]; char ans[50]; for(int i = 0; i < m; i++) { int cnt[20] = {0, }; for(int j = 0; j < n; j++) cnt[c[j][i] - 'A']++; int tmp = 0, idx = 0; for(int j = 0; j < 20; j++) if(tmp < cnt[j]) { tmp = cnt[j]; idx = j; } h += cnt[0] + cnt[2] + cnt[6] + cnt[19]; h -= cnt[idx]; ans[i] = idx + 'A'; } for(int i = 0; i < m; i++) cout << ans[i]; cout << endl << h; }
|