-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path32. UVa - 1368 DNA Consensus String.cpp
58 lines (57 loc) · 1.78 KB
/
32. UVa - 1368 DNA Consensus String.cpp
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
55
56
57
58
#include <iostream>
using namespace std;
string con;
int main()
{
int t;
cin>>t;
for(int l=0;l<t;l++){
int m,n;
cin>>m>>n;
string dna[m];
int sum=0;
for(int i=0;i<m;i++){
cin>>dna[i];
}
for(int i=0;i<n;i++){
int w[4];
w[0]=0;
w[1]=0;
w[2]=0;
w[3]=0;
for(int j=0;j<m;j++){
if(dna[j][i]=='A'){
w[0]++;
}
else if(dna[j][i]=='C'){
w[1]++;
}
else if(dna[j][i]=='G'){
w[2]++;
}
else if(dna[j][i]=='T'){
w[3]++;
}
}
if((w[0]>w[1]&&w[0]>w[2]&&w[0]>w[3])||(w[0]==w[1] && w[0]==w[2] && w[0]==w[3] )||(w[0]==w[1]&&w[0]==w[2]&&w[0]>w[3])||(w[0]==w[3]&&w[0]==w[2]&&w[0]>w[1])||(w[0]==w[1]&&w[0]==w[3]&&w[0]>w[2])||(w[0]>w[1]&&w[0]>w[2]&&w[0]==w[3])||(w[0]>w[1]&&w[0]>w[3]&&w[0]==w[2])||(w[0]>w[2]&&w[0]>w[3]&&w[0]==w[1])){
con+='A';
sum=sum+w[1]+w[2]+w[3];
}
else if((w[1]>w[0]&&w[1]>w[2]&&w[1]>w[3])||(w[1]==w[2]&&w[1]==w[3])||(w[1]>w[2]&&w[1]==w[3])||(w[1]>w[3]&&w[1]==w[2])){
con+='C';
sum=sum+w[0]+w[2]+w[3];
}
else if((w[2]>w[1]&&w[2]>w[0]&&w[2]>w[3])||(w[2]==w[3])){
con+='G';
sum=sum+w[1]+w[0]+w[3];
}
else if(w[3]>w[1]&&w[3]>w[2]&&w[3]>w[0]){
con+='T';
sum=sum+w[1]+w[2]+w[0];
}
}
cout<<con<<endl;
cout<<sum<<endl;
con.clear();
}
}