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

    xiaoxiao2024-11-30  5

    例子:

    abcd   cdab  ----->   true

    1ab2  ab12  ------>   false

    // // main.cpp // 判断两个字符串是否互为旋转词 // // Created by zjl on 16/8/13. // Copyright © 2016年 zjl. All rights reserved. // #include <iostream> #include <string> using namespace std; bool isRotation(string a, string b){ if(a.size() == 0 || b.size() == 0 || a.size() != b.size()) return false; string s = a + a; int res = s.find(b); return res != -1; } int main(int argc, const char * argv[]) { // insert code here... string a = "abcd"; bool b = isRotation(a, "cdba"); cout << b << endl; return 0; }

    转载请注明原文地址: https://ju.6miu.com/read-1294138.html
    最新回复(0)