#include <iostream>
#include <algorithm>
#include <string>
bool isRotation(const std::string& lhs, std::string& rhs);
int main()
{
std::string lhs, rhs;
std::cin >> lhs >> rhs;
std::cout << std::boolalpha << isRotation(lhs, rhs);
system("pause");
return 0;
}
bool isRotation(const std::string& lhs, std::string& rhs)
{
if (lhs.length() < 1 || rhs.length() < 1 || lhs.length() != rhs.length())
return false;
rhs += rhs; //如果两个词互为旋转词 则第一个词一定可以在两个第二个词构成的词中是子串
if (strstr(rhs.c_str(), lhs.c_str()))
return true;
else
return false;
}
C++判断两个字符串是否互为旋转词
最新推荐文章于 2022-04-29 22:30:17 发布