判断两个字符串是否互旋转词

#include 
#include 
#include 
using namespace std;
 
bool isRotation(string &str1 , string &str2)
{
    string temp;
    temp=str2+str2;
    if(temp.find(str1)!=temp.npos)
        return true;
    else
        return false;
}
int main()
{
    int m,n;
    cin>>m>>n;
    string str1;
    string str2;
    cin>>str1;
    cin>>str2;
    bool res;
    res=isRotation(str1,str2);
    if(res==1)
        cout<<"YES"<

1/string 定义的变量可以直接相加以达到拼接的目的
2/algorithm 中find函数的使用
3/如果查找的结果是string.npos,其代表着没有找到。

你可能感兴趣的:(判断两个字符串是否互旋转词)