Source Code
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
typedef long long ll;
        
        
        
	int main(){
		
		string a,b;
		cin>>a>>b;
		
		string a1="";
		
		for(int i=0;i<int(a.size());i++){
			string tst1="",tst2="";
			int j = (b.size() + i -(a.size() - i))/2;
			if(j>int(b.size()) || j<0)continue;
			
			j = int(b.size())-j;
			
			for(int k=j;k<int(b.size());k++)tst1+=b[k];
			for(int k=i;k<int(a.size());k++)tst1+=a[k];
			
			for(int k=0;k<j;k++)tst2+=b[k];
			for(int k=0;k<i;k++)tst2+=a[k];
			
			
			if(tst1 == tst2){
				cout<<tst1;
				return 0;
				}
			}
		cout<<-1;
	return 0;
	}
Copy
Right into Two Bahaa
GNU G++17
85 ms
924 KB
Accepted