Affinity string
Time limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 8523 Accepted Submission (s): 3893
Problem description People with age growth is the bigger the wiser or the bigger the more stupid, this is a question that deserves the world's scientists to think about, the same question Eddy has been thinking, because he knew in a very small time how affinity string judgment, but found that Now grow up and do not know how to judge the affinity string, so he had to again to ask smart and helpful you to solve the problem.
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 has multiple 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 S2 is the affinity string of the S1, outputs "yes" and, conversely, outputs "no". The output for each group of tests is one row.
Sample Input
Aabcdcdaaasdasdf
Sample Output
Yesno
Authoreddy
Recommendlcy | We have carefully selected several similar problems for you:2201 3068 2202 2200 2206
Expand the ring into a chain, then KMP match it.
/************************************************************************* > File Name:hdu2203.cpp > Author: ALex > Mail: [email protected] > Created time:2015 January 05 Monday 11:06 38 seconds ******************************* /#include <map> #include <set> #include <queue> #include <stack> #include <vector> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm>using namespace std;const int N = 100010;int Next[n]; Char Str[n];char text[n << 1];void get_next () {int len = strlen (str); int j = 0;int k = -1;next[0] = -1;while (J < Len) {if (k = =-1 | | str[j] = = Str[k]) {next[++j] = ++k;} Else{k = Next[k];}} BOOL KMP () {int len1 = strlen (text); int len2 = strlen (str); int i = 0;int J = 0;while (J < len2 && I < len1) {I F (J = =-1 | | str[j] = = Text[i]) {++i;++j;} Else{j = Next[j];}} if (j = = Len2) {return 1;} Return 0;} int main () {while (~scanf ("%s%s", text, str)) {get_next (); int len = strlen (text); for (int i = len; i < 2 * len-1; ++i) { Text[i] = Text[i-len];} Text[2 * len-1] = ' + '; if (KMP ()) {printf ("yes\n");} else{printf ("no\n");}} return 0;}
hdu2203--Affinity String