编程之美——字符串移位包含问题
#include<iostream>
#include<string>
using namespace std;
bool cycle(string res, string des)
{
int res_size = res.size();
int des_size = des.size();
if(res_size < des_size)
return false;
for(int i = 0; i < res_size; i++)
{
if(res[i] == des[0])
{
int tmp = i + 1;
int j = 1;
for(; j < des_size; j++)
{
if(res[tmp % res_size] != des[j])
break;
tmp++;
}
if(j == des_size)
return true;
}
}
return false;
}
int main()
{
string res,des;
res = "AABBCD";
des = "CDAA";
if(cycle(res,des))
{
cout<<"true"<<endl;
}
else
{
cout<<"false"<<endl;
}
cin.get();
return 0;
}