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 INPUTAABCD Cdaa ASD ASDF Sample Outputyes no//Generally, like this relatively simple, can be used KMP the topic, a part of the strstr//char can be solved with the function *strstr (STR1, STR2)//return value: If STR2 is a substring of str1, returns the address of the first occurrence of str2 at STR1, or null if STR2 is not a substring of str1.
#include <iostream>#include<cstring>#include<cstdio>using namespacestd;Chars1[250000],s2[100000];intMain () { while(cin>>s1>>S2) { intStr=strlen (S1); for(inti=str;i<2*str-1; i++) S1[i]=s1[i-STR]; Char*ch=strstr (S1,S2); if(ch==NULL) cout<<"No"<<Endl; Elsecout<<"Yes"<<Endl; } return 0;}
HDU2203: Affinity String