编程之美——字符串移位包含问题

编程之美——字符串移位包含问题

#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;
}
    原文作者:ranyongqing
    原文地址: https://blog.csdn.net/ranyongqing/article/details/38439907
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞