标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4521 Accepted Submission(s): 1639
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<string> #include<iostream> #include<cstring> #include<cmath> #include<stack> #include<queue> #include<vector> #include<map> #include<stdlib.h> #include<algorithm> #define LL __int64 #define FIN freopen("in.txt","r",stdin) using namespace std; const int MAXN=50000+5; char str[MAXN*2],b[MAXN]; int nex[MAXN*2]; int n; void getnext() { int j=0,k=-1; nex[0]=-1; while(j<n) { if(k==-1 || str[j]==str[k]) nex[++j]=++k; else k=nex[k]; } } int main() { //FIN; while(scanf("%s %s",str,b)!=EOF) { int len1=strlen(str),len2=strlen(b); strcat(str,b); n=strlen(str); getnext(); while(nex[k]>len1 || nex[k]>len2) k=nex[k]; if(nex[n]==0) printf("0\n"); else { for(int i=0;i<len;i++) printf("%c",str[i]); printf(" %d\n",len); } } return 0; }
HDU 2594 Simpsons’ Hidden Talents (KMP)
标签:
原文地址:http://www.cnblogs.com/clliff/p/4725494.html