The title requirement is to parse several strings and get an optimal string that satisfies the appended and minima of the different characters required by the string. If there are multiple solutions, the output dictionary order is minimal.
Note: At the end of the string, you must add
1#include <cstdio>2#include <algorithm>3#include <cstring>4 using namespacestd;5 6 Const intmaxn=1005;7 Chardna[ -][MAXN];8 structnode{9 inti;Ten CharN; One BOOL operator< (ConstNode RHS)Const{ A returni<rhs.i | | (I==rhs.i && n>RHS.N); - } - }; the - voidDo (); - intHamming (CharS1[],CharS2[],intlen); - + intMain () { - //freopen ("In.txt", "R", stdin); + intN; Ascanf"%d",&N); at for(intI=0; i<n;i++) - Do (); - return 0; - } - - voidDo () { in intM,n; -scanf"%d%d",&m,&n); to intA[MAXN],C[MAXN],G[MAXN],T[MAXN]; +memset (A,0,sizeof(A)); -memset (C,0,sizeof(C)); thememset (G,0,sizeof(G)); *memset (T,0,sizeof(T)); $ Panax Notoginseng for(intI=0; i<m;i++){ -scanf"%s", Dna[i]); the for(intj=0; j<n;j++){ + if(dna[i][j]=='A') a[j]++; A if(dna[i][j]=='C') c[j]++; the if(dna[i][j]=='G') g[j]++; + if(dna[i][j]=='T') t[j]++; - } $ } $ CharDNA_MIN[MAXN]; - for(intI=0; i<maxn;i++) -dna_min[i]=' /'; the for(intI=0; i<n;i++){ -Node a[4]={{a[i],'A'},{c[i],'C'},{g[i],'G'},{t[i],'T'}};WuyiSort (a,a+4); thedna_min[i]=a[3].N; - } Wu - intans=0; About for(intI=0; i<m;i++){ $ans+=Hamming (dna_min,dna[i],n); - } -printf"%s\n%d\n", Dna_min,ans); - return; A } + the intHamming (CharS1[],CharS2[],intLen) { - intans=0; $ for(intI=0; i<len;i++) the if(s1[i]!=S2[i]) theans++; the returnans; the}
1368.DNA Consensus String