Source Code
#include <bits/stdc++.h>
using namespace std;
#define len(s) (int)s.size()
#define all(a) a.begin() , a.end()
#define int  long long
#define endl '\n'
#define MOD 1000000007
int min(int a, int b) { return (a < b) ? a : b; }
int max(int a,int b) { return (a > b) ? a : b; }
void solve() {
    int n;
    cin >> n ;
    string s , t ;
    cin >> s >> t;
    if(s == t) {
        cout << 0;
        return;
    }
    for(int i = 0 ; i < n ; i++){
        string str =  s.substr( i+1) + s.substr( 0 , i+1) ;
        if(str.find(t)){
            cout << 1;
            return;
        }
     }
    cout << 0 ;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
        cout << endl;
    }
}
Copy
Split and Swap saifomar
GNU G++17
11 ms
1.4 MB
Accepted