HDU 2203 亲和串 ---kmp
在字符串s1后再接上s1,形成新的字符串,再在s1中寻找是否有s2的子串,若有则为亲和串.
#include <iostream> #include <cstring> using namespace std; #define maxn 100005 char a[maxn]; char b[maxn]; char c[maxn*2]; int main() { while(cin>>a>>b) { strcpy(c,a); strcat(c,a); if(strstr(c,b)!=0) cout<<"yes"<<endl; else cout<<"no"<<endl; } return 0; }