POJ3080:Blue Jeans
2013-12-08 20:04
323 查看
Description
TheGenographicProjectisaresearchpartnershipbetweenIBMandTheNationalGeographicSocietythatisanalyzingDNAfromhundredsofthousandsofcontributorstomaphowtheEarthwaspopulated.
AsanIBMresearcher,youhavebeentaskedwithwritingaprogramthatwillfindcommonalitiesamongstgivensnippetsofDNAthatcanbecorrelatedwithindividualsurveyinformationtoidentifynewgeneticmarkers.
ADNAbasesequenceisnotedbylistingthenitrogenbasesintheorderinwhichtheyarefoundinthemolecule.Therearefourbases:adenine(A),thymine(T),guanine(G),andcytosine(C).A6-baseDNAsequencecouldberepresentedasTAGACC.
GivenasetofDNAbasesequences,determinethelongestseriesofbasesthatoccursinallofthesequences.
Input
Inputtothisproblemwillbeginwithalinecontainingasingleintegernindicatingthenumberofdatasets.Eachdatasetconsistsofthefollowingcomponents:
Asinglepositiveintegerm(2<=m<=10)indicatingthenumberofbasesequencesinthisdataset.
mlineseachcontainingasinglebasesequenceconsistingof60bases.
Output
Foreachdatasetintheinput,outputthelongestbasesubsequencecommontoallofthegivenbasesequences.Ifthelongestcommonsubsequenceislessthanthreebasesinlength,displaythestring"nosignificantcommonalities"
instead.Ifmultiplesubsequencesofthesamelongestlengthexist,outputonlythesubsequencethatcomesfirstinalphabeticalorder.
SampleInput
SampleOutput
TheGenographicProjectisaresearchpartnershipbetweenIBMandTheNationalGeographicSocietythatisanalyzingDNAfromhundredsofthousandsofcontributorstomaphowtheEarthwaspopulated.
AsanIBMresearcher,youhavebeentaskedwithwritingaprogramthatwillfindcommonalitiesamongstgivensnippetsofDNAthatcanbecorrelatedwithindividualsurveyinformationtoidentifynewgeneticmarkers.
ADNAbasesequenceisnotedbylistingthenitrogenbasesintheorderinwhichtheyarefoundinthemolecule.Therearefourbases:adenine(A),thymine(T),guanine(G),andcytosine(C).A6-baseDNAsequencecouldberepresentedasTAGACC.
GivenasetofDNAbasesequences,determinethelongestseriesofbasesthatoccursinallofthesequences.
Input
Inputtothisproblemwillbeginwithalinecontainingasingleintegernindicatingthenumberofdatasets.Eachdatasetconsistsofthefollowingcomponents:
Asinglepositiveintegerm(2<=m<=10)indicatingthenumberofbasesequencesinthisdataset.
mlineseachcontainingasinglebasesequenceconsistingof60bases.
Output
Foreachdatasetintheinput,outputthelongestbasesubsequencecommontoallofthegivenbasesequences.Ifthelongestcommonsubsequenceislessthanthreebasesinlength,displaythestring"nosignificantcommonalities"
instead.Ifmultiplesubsequencesofthesamelongestlengthexist,outputonlythesubsequencethatcomesfirstinalphabeticalorder.
SampleInput
3 2 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 3 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA GATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA GATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA 3 CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC ACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
SampleOutput
nosignificantcommonalities AGATAC CATCATCAT
找出n个串中最长的公共串,并且要求字典序最大
直接枚举第一串的所有子串,然后与后面的所有串进行比较即可
#include<stdio.h>
#include<string.h>
#include<algorithm>
usingnamespacestd;
charstr[15][65];
charsub[65];
charans[65];
intlen;
intmain()
{
intt,i,j,k,n,maxn;
scanf("%d",&t);
while(t--)
{
maxn=0;
scanf("%d",&n);
memset(ans,'\0',sizeof(ans));
for(i=1;i<=n;i++)
scanf("%s",str[i]);
for(i=1;i<=60;i++)
{
intfind=0;
for(j=0;j<=60-i;j++)
{
len=0;
intcheck=1;
for(k=j;;k++)
{
sub[len++]=str[1][k];
if(len==i)
break;
}
sub[len]='\0';
for(k=2;k<=n;k++)
{
if(!strstr(str[k],sub))
{
check=0;
break;
}
}
if(check)
{
find=1;
if(strlen(ans)<strlen(sub))
strcpy(ans,sub);
elseif(strcmp(ans,sub)>0)
strcpy(ans,sub);
}
}
if(!find)
break;
}
if(strlen(ans)<3)
printf("nosignificantcommonalities\n");
else
printf("%s\n",ans);
}
return0;
}
相关文章推荐
- POJ3080 Blue Jeans
- Blue Jeans---poj3080(kmp+暴力求子串)
- poj3080 Blue Jeans(串的暴力枚举)
- POJ3080-Blue Jeans
- POJ3080 Blue Jeans(kmp & 暴力)
- poj3080 Blue Jeans
- POJ3080-Blue Jeans
- Blue Jeans(poj3080,后缀数组,求最长公共子串)
- poj3080--Blue Jeans(字符串匹配)
- POJ3080:Blue Jeans(后缀数组)
- POJ3080 Blue Jeans
- POJ3080-Blue Jeans
- poj3080 Blue Jeans
- Blue Jeans poj3080
- POJ3080Blue Jeans(暴力)
- POJ3080 Blue Jeans
- POJ3080 Blue Jeans
- POJ3080Blue Jeans
- POJ3080 Blue Jeans
- Blue Jeans(poj3080简单字符串匹配)