标签:int series related OWIN def cep 题目 spl aaa
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 20966 | Accepted: 9279 |
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
#include<cstdio> #include<iostream> #include<cstring> #include<memory> #include<algorithm> using namespace std; #define mod 360000 string a,b[15]; int next1[65]; int sum; void getnext(string s,int next1[],int m) { next1[0]=0; next1[1]=0; for(int i=1; i<m; i++) { int j=next1[i]; while(j&&s[i]!=s[j]) j=next1[j]; if(s[i]==s[j]) next1[i+1]=j+1; else next1[i+1]=0; } } int kmp(string ss,string s,int next1[],int n,int m) { getnext(s,next1,m); int j=0; for(int i=0; i<n; i++) { while(j&&s[j]!=ss[i]) j=next1[j]; if(s[j]==ss[i]) j++; if(j==m) { return 1; } } return 0; } int main() { int t; string ans; scanf("%d",&t); while(t--) { ans=""; int n; scanf("%d",&n); for(int i=0; i<n; i++) cin>>b[i]; int l=b[0].size(); for(int i=1; i<=l; i++)//字串长度 { for(int j=0; j<=l-i; j++)//字串起点 { a=b[0].substr(j,i);//substr 起点是j,长度为i bool flag=1; for(int k=1; k<n; k++) { if(!kmp(b[k],a,next1,b[k].size(),a.size())) flag=0; } if(flag) { if(ans.size()<a.size()) ans=a; else if(ans.size()==a.size()) ans=min(ans,a); } } } if(ans.size()<3) printf("no significant commonalities\n"); else cout<<ans<<endl; } return 0; }
POJ 3080 Blue Jeans 找最长公共子串(暴力模拟+KMP匹配)
标签:int series related OWIN def cep 题目 spl aaa
原文地址:https://www.cnblogs.com/yinbiao/p/9457524.html