您的位置:首页 > 产品设计 > UI/UE

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
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: