借助C语言中的库函数strstr,可以避免写KMP;循环判断即可。
#include<iostream>
using namespace std;
int main()
{
char a[200001],b[100001];
int i,len;
bool f;
while(gets(a))
{
f=0;
gets(b);
if(strlen(b)>strlen(a)) cout<<"no"<<endl;
else
{
len=strlen(a);
if(strstr(a,b)) f=1;
else
for(i=0;i<len-1;i++)
{
a[len+i]=a[i];
a[len+i+1]='\0';
if(strstr(a+i,b))
{
f=1;
break;
}
}
if(f) cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
}
return 0;
}原文地址:http://blog.csdn.net/a809146548/article/details/44199709