题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2203
方法一:将str1复制给str,再将str接到str1后面,最后判断str2是否包含在str1中(此处用到了STL库中的strstr函数)
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
char str[100005],str1[100005],str2[100005];
while(scanf("%s%s",&str1,&str2)!=EOF)
{
strcpy(str,str1);
strcat(str1,str);
if(strstr(str1,str2)) cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
return 0;
}
方法二:使用KMP算法