UVa 1368.DNA Consus String

14735 ワード

ソースリンク:http://uva.onlinejudge.org/index.php?option=com_オンラインjudge&Itemid=8&page=show_problem&problem=4114
 
13845357
1368
DNA Consus String
Acceepted
C++
0.022
2014-07-07 12:29:30
 
  DNA Consus String
 
Figure 1.DNA(Deoxyribonucleic Acid)is the molecule which contains the genetic inststststininstininstininstinininsts.It consists of four differentnucleotids,namely Adenine,Thymine,Gunine,Gunine,and and ine,andand,and Cytototoinininine,andand Cytotoininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininng string(sequence of characters)consisting of the four characters A,T,G,and C.For example,a some we are given some part of a DNA strand which is compsed of the following sequence of nucleotides:
‘Thymine-Adenine-Adenine-Adenine-Tyntine-Thymine-Gine-Cyntine-Gine-Gine-Gine-Gine-Adenine-Thymine’
 
「The biologist Prof.Ahn found that a gene X comonlyexxxxxxxxxxxxxxxstands of five differentininininininininds of anims,namely dogs,Cashshshshshemones,Cashemommmyexininininexxststststststststs s s s s s s s s s s of fifififive dididididididifferentinininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininine very alike.See Figure 2.
 
 
 
DNA sequence of gene X
Cat:
GCATATGCTGGCA
Docg:
GCAAATGCTGGCA
Horse:
GCTAATGGGGGGTCCA
Cow:
GCAAATGCTGGCA
モンキー:
GCAAATCGGGGGAGCA
 
Figure 2.DNA sequences of gene X in five animls.
 
Prof.Ahn thought that huomans might also have the gene X and decided to search for the DNA sequence of X in hman DNA.However,before searching,heheshuld define a representaaateive DNA sequence of gene X because e sequences ararnot eexactlythe same the DNA of the five anmals. He decided to the Hamminininininininininininstrererererereesentinininininininininininininininininininininininininininininininininininininininininininininininininstststststststststststrerererererererereinininininininininininininininininininininininininininininininininininininexample、ザザザハmmindistance of therst stinininins s s s`AGCAT‘and`GGAAT.’The Hamminindistancs of these twoststinininins s 2 because the 1 st andthe 3 rd racters of the twoststininines.Using the Hamminininininininininininininininininininininininininininininininininininininininininininininininininininininininininininststststststststststststststininininininininininininininininininininininininininininininin1,…,sm of length n,the connsus error between a string y of length n and the set S isthe sum of the Hamming distancs between and each si in S.If the connsus error between y and S isthe minimummmmmunall posisisisisisiblblble stininininininininininininininststststststinininininininininininininins s s s s s s s stststststststststststststststinininininininininininininininininininininininininininininininininininininininininininin` GGAAT"the consensus string of the given streings`AGAAT"because the sum of the Hamming distance between`AGAAT"and the three streings 3 which is minimal.(In this case,the consensus string is String is unque,bustree the streene the Canese.)We use the consensus string as a representative of the DNA sequence.For the example of Figure 2 above,a consensus string of gene X is`GCAAATGGCTGCA"and the consensus erroris 7.
 
Input 
Your program is to read from standndinput.The input consists of T test cases.The number of test cases s s s is given in the first input.Each test case starts with a ininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininintetetetetetetetetersrsrsrsrsrsm andandandandandandandandandandands s s s s s n 1000)represents the length of the DNA sequences,repectively.In each of the next m lines,each DNA sequence is given.
Output 
Your program is to write to standar output.Print the consensus string in the first line of each case and the consensus error in the second case.If there exists more thone connsstring,print the lexicographications。
Sample Input 
 
3 

5 8 

TATGATAC 

TAAGCTAC 

AAAGATCC 

TGAGATAC 

TAAGATGT 

4 10 

ACGTACGTAC 

CCGTACGTAG 

GCGTACGTAT 

TCGTACGTAA 

6 10 

ATGTTACCAT 

AAGTTACGAT 

AACAAAGCAA 

AAGTTACCTT 

AAGTTACCAA 

TACTTACCAA

 
Sample Output 
 
TAAGATAC 

7 

ACGTACGTAA 

6 

AAGTTACCAA 

12

: Hamming , Hamming 。 Hamming , , 。


 1 #include <iostream>

 2 #include <cstring>

 3 #include <cstdio>

 4 #include <cstdlib>

 5 #include <cctype>

 6 #include <cmath>

 7 #include <algorithm>

 8 #include <numeric>

 9 using namespace std;

10 int main() {

11     int n, len, l; cin >> l;

12     string gene[55];

13     char TGCA[4];

14     while(l--) {

15         cin >> n >> len;

16         int cnt = 0;

17         for(int i = 0; i < n; i++) {

18             cin >> gene[i];

19         }

20 

21         for(int i = 0; i < len; i++) {

22             memset(TGCA, 0, sizeof(TGCA));

23             for(int j = 0; j < n; j++) {

24                 if(gene[j][i] == 'T') {

25                     TGCA[0] ++;

26                 } else if (gene[j][i] == 'G') {

27                     TGCA[1] ++;

28                 } else if (gene[j][i] == 'C') {

29                     TGCA[2] ++;

30                 } else if (gene[j][i] == 'A') {

31                     TGCA[3] ++;

32                 }

33 

34             }

35 

36             if(TGCA[0] > TGCA[1] && TGCA[0] > TGCA[2] && TGCA[0] > TGCA[3]) {

37                 cout << 'T';

38                 cnt += TGCA[1] + TGCA[2] + TGCA[3];

39             } else if(TGCA[1] >= TGCA[0] && TGCA[1] > TGCA[2] && TGCA[1] > TGCA[3] ) {

40                 cout << 'G';

41                 cnt += TGCA[0] + TGCA[2] + TGCA[3];

42             } else if(TGCA[2] >= TGCA[0] && TGCA[2] >= TGCA[1] && TGCA[2] > TGCA[3]) {

43                 cout << 'C';

44                 cnt += TGCA[1] + TGCA[0] + TGCA[3];

45             } else if(TGCA[3] >= TGCA[0] && TGCA[3] >= TGCA[1] && TGCA[3] >= TGCA[2]) {

46                 cout << 'A';

47                 cnt += TGCA[1] + TGCA[2] + TGCA[0];

48             }

49 

50         }

51         cout << endl << cnt << endl;

52     }

53     return 0;

54 }