Source Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string a, b;
    cin >> a >> b;
    string tempa = "",tempb = "";
    if(a == b){
        cout << a << '\n';
        return 0;
    }
    for(int i = 0; i < a.size(); i++){
        tempa = "";
        tempb = "";
        for(int j = b.size() - 1; j >= 0; j--){
            tempb = b.substr(j,b.size()- 1);
            tempa = tempb;
            tempa += a.substr(i, a.size()-1);
            if(tempa ==(b.substr(0,j) + a.substr(0,i))){
                cout << tempa << '\n';
                return 0;
            }
        }
    }
    cout << -1;
}
Copy
Right into Two monther abu zaina1
GNU G++17
0 ms
832 KB
Wrong Answer