标签:des os io strong ar for art div sp
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 12295 | Accepted: 5337 |
Description
Input
Output
Sample Input
3 2 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 3 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATA GATACTAGATACTAGATACTAGATACTAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA GATACCAGATACCAGATACCAGATACCAAAGGAAAGGGAAAAGGGGAAAAAGGGGGAAAA 3 CATCATCATCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC ACATCATCATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AACATCATCATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
Sample Output
no significant commonalities AGATAC CATCATCAT
Source
仔细就好,了解了strstr函数。。。
/* ** 作者** 功能:查找最长公共字串 ** poj3080 */ #include<iostream> #include<cstring> using namespace std; int main() { int t; cin>>t; while(t--) { int n; cin>>n; int i,j,k; char str[12][65],ans[65],sub[65]; for(i=0;i<n;i++) cin>>str[i]; ans[0]='\0'; for(i=3;i<=60;i++)//枚举字串长度 { bool fd=false;//是否有公共字串判断 for(j=0;j<=60-i;j++)//枚举字串起点 { int len=0;//字串长度复制记录 for(k=j;len<i;k++) { sub[len++]=str[0][k]; } sub[len]='\0';//取出字串gai bool ffdd=false;//该字串是否满足 //接下来对比其他串 for(k=1;k<n;k++) { if(!strstr(str[k],sub)) { ffdd=true; break; } } //如果该字串满足,则与ans比较并赋值 if(!ffdd) { if(strlen(ans)<strlen(sub)) { strcpy(ans,sub); }else if(strlen(ans)==strlen(sub)&&strcmp(sub,ans)<0) { strcpy(ans,sub); } fd=true; } } if(!fd) break; } if(strlen(ans)!=0) { cout<<ans<<endl; }else{ cout<<"no significant commonalities"<<endl; } } return 0; }
标签:des os io strong ar for art div sp
原文地址:http://blog.csdn.net/fljssj/article/details/38925595