标签:
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10862 Accepted Submission(s): 4940
#include<cstdio> #include<cstring> using namespace std; char a[200005]; char b[100005]; int lena,lenb; int next[100005]; void getnext() { int i=0,k=-1; next[0]=-1; while(i<lenb) { if(k==-1||b[i]==b[k]) { i++; k++; next[i]=k; } else k=next[k]; } } int KMP() { getnext(); int i=0,j=0; while(i<lena) { if(j==-1||a[i]==b[j]) { i++; j++; } else j=next[j]; if(j==lenb) return i-j+1; } return -1; } int main() { while(scanf("%s%s",a,b)!=EOF) { lena=strlen(a); lenb=strlen(b); for(int i=lena;i<lena+lena;i++) { a[i]=a[i-lena]; } lena+=lena; if(KMP()!=-1) printf("yes\n"); else printf("no\n"); } return 0; }
#include<cstdio> #include<cstring> using namespace std; char a[200005]; char b[100005]; char t[100005]; int main() { while(scanf("%s%s",a,b)!=EOF) { strcpy(t,a); strcat(a,t); if(strstr(a,b)!=NULL) printf("yes\n"); else printf("no\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/program-ccc/p/5199324.html