Affinity string
Time limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 9047 Accepted Submission (s): 4121
Problem Description
People with the age of growth is the bigger the wiser or the bigger the more stupid, this is a question worthy of the world's scientists thinking, the same problem Eddy has been thinking, because he knew in a very small time how to judge the affinity string, but found that now grow up without knowing how to judge the affinity string, So he had to ask the smart and helpful you to solve the problem again.
The definition of affinity string is this: given two strings S1 and S2, if the S2 can be included in S1 by S1 cycle, then we say S2 is the affinity string of S1.
Input
There are several sets of test data, the first row of each group of data contains the input string s1, the second line contains the input string s2,s1 and s2 length are less than 100000.
Output
If the S2 is a s1 affinity string, the output is "yes" and, conversely, the output "no". The output for each group of tests is one row.
Sample Input
Aabcd
Cdaa
Asd
ASDF
Sample Output
Yes
No
Author
Eddy
#include <iostream>#include <cstdio>#include <cstring>using namespace STD;Const intM =1e5+5;CharS1[M], s2[m];intNEXT[M];voidGet_next (CharS[]) {memset(Next,0,sizeof(Next)); next[0] = -1;intj =-1, i =0;intLen =strlen(s); while(I < Len) {if(j = =-1|| S[i] = = S[j]) {++i; + + j; Next[i] = j; }Elsej = Next[j]; }}BOOLSolve () {intI, J;intLen1 =strlen(S1);intLen2 =strlen(S2); i =0, j =0; while(I < len1+len2&& J < Len2) {if(j = =-1|| S1[I%LEN1] = = S2[j]) {++i; ++j;//if (j = = Len2) return 1;}Elsej = Next[j]; }if(j = = Len2)return 1;return 0;}intMain () { while(scanf("%s%s", s1, s2) = =2){intLen1 =strlen(S1);intLen2 =strlen(S2);if(Len1 < Len2) {printf("no\n");Continue; } get_next (S2);//printf ("Dsaf"); printf("%s\n", Solve ()?"Yes":"No"); }return 0;}
Hdoj 2203 Affinity string "KMP"