-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1969.cpp
More file actions
54 lines (50 loc) · 1.01 KB
/
1969.cpp
File metadata and controls
54 lines (50 loc) · 1.01 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string DNA[1000];
char minHammingDNA[51];
int N, M, min= 10000, result;
char returnChar(int a, int t, int g, int c, int max) {
if (a == max) return 'A';
else if (c == max)return 'C';
else if (g == max) return 'G';
else if (t == max) return 'T';
else return 0;
}
int compare() {
int hammingDistance = 0;
for (int i = 0; i < M; i++) {
int a = 0, t = 0, g = 0, c = 0;
for (int j = 0; j < N; j++) {
switch (DNA[j][i]) {
case 'A':
a++;
break;
case 'T':
t++;
break;
case 'G':
g++;
break;
case 'C':
c++;
break;
}
}
int maxPos = max(a > t ? a : t, g > c ? g : c);
minHammingDNA[i] = returnChar(a, t, g, c, maxPos);
hammingDistance += (a + t + g + c - maxPos);
}
return hammingDistance;
}
int main() {
cin >> N >> M;
for (int i = 0; i < N; i++) {
cin >> DNA[i];
}
int result = compare();
for (int i = 0; i < M; i++)cout << minHammingDNA[i];
cout << endl << result;
return 0;
}