字符串移位包含问题(strstr+c_str)C++

#include <bits/stdc++.h>

using namespace std;

string a, b;

int main()
{
    cin >> a >> b;
    if (a.size() < b.size()) swap(a, b);
    
    string c = a + a;
    
    if (c.find(b) != string::npos) cout << "true" << endl;
    else cout << "false" << endl;
    
    return 0;
}
#include <bits/stdc++.h>

using namespace std;

string a, b;

int main()
{
    cin >> a >> b;
    if (a.size() < b.size()) swap(a, b);
    
    string c = a + a;
    
    if (strstr(c.c_str(), b.c_str())) cout << "true" << endl;
    else cout << "false" << endl;
    
    return 0;
}
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    string a, b;

    cin >> a >> b;
    if (a.size() < b.size()) swap(a, b);

    for (int i = 0; i < a.size(); i ++ )
    {
        a = a.substr(1) + a[0];

        for (int j = 0; j + b.size() <= a.size(); j ++ )
        {
            int k = 0;
            for (; k < b.size(); k ++ )
                if (a[j + k] != b[k])
                    break;
            if (k == b.size())
            {
                puts("true");
                return 0;
            }
        }
    }

    puts("false");

    return 0;
}