判斷倆個字符串是否互爲旋轉詞

#include <iostream>
#include <string>
using namespace std;
bool isRotation(string a, string b)
{
    if(a.size() != b.size())
        return false;
    string b2 = b + b;
    return b2.find(a) == string::npos ? false : true;
}
int main()
{
    cout << isRotation("abcd", "cdab") << endl;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章