标签:
题目:ZOJ-3132-DNA Consensus String
1 #include <iostream>
2 #include<stdio.h>
3 #include<stdlib.h>
4 #include<string.h>
5 #include<math.h>
6 #include<algorithm>
7
8 using namespace std;
9
10 char str[55][1010];
11 struct dna
12 {
13 int a,c,g,t;
14 } d[1010];
15
16 int main()
17 {
18 int t,m,n,i,j,ans,maxx;
19 char s[1010];
20 scanf("%d",&t);
21 while(t--)
22 {
23 scanf("%d%d",&m,&n);
24 for(i=0; i<n; i++)
25 d[i].a=d[i].c=d[i].g=d[i].t=0;
26 for(i=0; i<m; i++)
27 {
28 scanf("%s",s);
29 for(j=0; j<n; j++)
30 if(s[j]==‘A‘) d[j].a+=1;
31 else if(s[j]==‘C‘) d[j].c+=1;
32 else if(s[j]==‘G‘) d[j].g+=1;
33 else d[j].t+=1;
34 }
35 ans=0;
36 for(i=0; i<n; i++)
37 {
38 s[i]=‘A‘;
39 maxx=d[i].a;
40 if(d[i].c>maxx)
41 {
42 s[i]=‘C‘;
43 maxx=d[i].c;
44 }
45 if(d[i].g>maxx)
46 {
47 s[i]=‘G‘;
48 maxx=d[i].g;
49 }
50 if(d[i].t>maxx)
51 {
52 s[i]=‘T‘;
53 maxx=d[i].t;
54 }
55 ans+=m-maxx;
56 }
57 s[n]=‘\0‘;
58 printf("%s\n%d\n",s,ans);
59 }
60 return 0;
61 }
标签:
原文地址:http://www.cnblogs.com/alohagin/p/4279111.html