标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4976 Accepted Submission(s): 1815
/* ID: LinKArftc PROG: 2594.cpp LANG: C++ */ #include <map> #include <set> #include <cmath> #include <stack> #include <queue> #include <vector> #include <cstdio> #include <string> #include <utility> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define eps 1e-8 #define randin srand((unsigned int)time(NULL)) #define input freopen("input.txt","r",stdin) #define debug(s) cout << "s = " << s << endl; #define outstars cout << "*************" << endl; const double PI = acos(-1.0); const double e = exp(1.0); const int inf = 0x3f3f3f3f; const int INF = 0x7fffffff; typedef long long ll; const int maxn = 100010; char str[maxn], str1[maxn]; int Next[maxn]; void getNext(char *p) { int len = strlen(p); int i = 0, j = -1; Next[i] = j; while (i < len) { if (j == -1 || p[i] == p[j]) { i ++; j ++; Next[i] = j; } else j = Next[j]; } } int main() { while (~scanf("%s %s", str, str1)) { int len1 = strlen(str); int len2 = strlen(str1); strcat(str, str1); getNext(str); int len = strlen(str); int cnt = Next[len]; while (cnt > len1 || cnt > len2) { cnt = Next[cnt]; } if (cnt == 0) printf("0\n"); else { for (int i = 0; i < cnt; i ++) printf("%c", str[i]); printf(" %d\n", cnt); } } return 0; }
标签:
原文地址:http://www.cnblogs.com/LinKArftc/p/4959685.html