Pro-stringTime
limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 8049 Accepted Submission (s): 3719
Problem description People with the age of growth is the bigger the wiser or the bigger the more stupid, this is a question for scientists around the world, the same question Eddy has been thinking, because he at a very small time to know how affinity string inference. But found that now grow up and do not know how to infer affinity string, so he just good and once again to ask smart and helpful you to solve the problem.
The definition of affinity string is this: given two strings S1 and S2, assuming that the S2 can be included in S1 by S1 cyclic shift, then we say S2 is the affinity string of S1.
Input has multiple sets of test data. The first row of each set of data includes the input string S1, and the second line includes the input string s2. The length of S1 and S2 is less than 100000.
The output assumes that S2 is a s1 affinity string. The output is "yes" and vice versa. Output "no". One row for each set of test outputs.
Sample Input
Aabcdcdaaasdasdf
Sample Output
Yesno
Chinese problem, test instructions not much, directly on the code:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cmath> #include <string> #include <map> #include <stack> #include <vector> #include <set > #include <queue> #pragma comment (linker, "/stack:102400000,102400000") #define MAXN 100010#define MAXN 2005# Define mod 1000000009#define INF 0x3f3f3f3f#define pi ACOs ( -1.0) #define EPS 1e-6typedef Long long ll;using namespace std;c Har str[2*maxn],pstr[2*maxn];int nextval[2*maxn];void get_nextval () {int Plen=strlen (PSTR); int i=0,j=-1; Nextval[0]=-1; while (I<plen) {if (j==-1| | Pstr[i]==pstr[j]) {i++; j + +; if (Pstr[i]!=pstr[j]) nextval[i]=j; else Nextval[i]=nextval[j]; } else j=nextval[j]; }}bool KMP () {int i=0,j=0; int Len=strlen (str); int Plen=strlen (PSTR); while (I<len&&j<plen) {if (j==-1|| Str[i]==pstr[j]) {i++; j + +; } else j=nextval[j]; } if (J==plen) return true; return false;} int main () {while (~scanf ("%s%s", Str,pstr)) {int Len=strlen (str); for (int i=0;i<len;i++) str[len+i]=str[i]; str[len+i]= ' + '; Get_nextval (); if (KMP ()) printf ("yes\n"); else printf ("no\n"); } return 0;} /*aabcdcdaaasdasdf*/
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
Kissing string (hdu 2203 KMP)