-
Notifications
You must be signed in to change notification settings - Fork 2
/
DNA序列.cpp
66 lines (59 loc) · 1.03 KB
/
DNA序列.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
59
60
61
62
63
64
65
66
#include<stdio.h>
#include<map>
using namespace std;
char buf[51][1001];
char findchar(map<char, int> &mm,int &count){
map<char, int>::iterator beg = mm.begin(), end = mm.end(), pos1,pos2;
pos1 = pos2 = beg;
pos2++;
char c;
while(pos2!=end){
int t = pos2->second;
if(t>pos1->second){
pos1 = pos2;
}
else if(t == pos1->second){
if(pos2->first < pos1->first){
pos1 = pos2;
}
}
pos2++;
}
c = pos1->first;
pos2 = beg;
while(pos2!=end){
if(pos2->first!=c){
count+=pos2->second;
}
pos2++;
}
return c;
}
int main(){
int t;
scanf("%d", &t);
map<char, int> mm;
while(t--){
int m, n;
scanf("%d %d", &m, &n);
char ans[n];
int count = 0,pos=0;
for(int i = 0; i<m;i++){
scanf("%s", buf[i]);
}
for(int l = 0; l<n;l++){
mm.clear();
for(int h = 0; h<m;h++){
char c = buf[h][l];
mm[c]++; // ¼ÆËã³ö¸ÃÁÐAGCTµÄÊýÄ¿
}
char c = findchar(mm, count);
ans[pos++] = c;
}
for(int i = 0; i<n;i++){
printf("%c", ans[i]);
}
printf("\n%d\n", count);
}
return 0;
}