您的位置:首页 > 其它

字符串循环移位包含

2012-02-28 20:03 197 查看
给定两个字符串s1和s2,要求判定s2能否可以被s1循环移位得到的字符串包含。

#include <iostream>using namespace std;

bool fun(char *s1,char *s2)
{
int n=strlen(s1);
int m=strlen(s2);
for(int i=0,j=0;i<n;++i,j=0)
{
int k=i;
while(s1[k%n] == s2[j])
{
++k;
++j;
if(j == m)
{
return true;
}
}
}
return false;
}

void main()
{
char s1[]="AABBCD";
char s2[]="DAA";
cout<<fun(s1,s2)<<endl;
system("pause");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: