Source Code
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define TEST int t;cin>>t;while(t--)
#define rep(i,n) for(int i=0;i<n;i++)
#define fr first
#define sc second
#define popcount __builtin_popcountll
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const ll mod=1000000007;
typedef vector<int,int> p1;
typedef vector<ll,ll> p2;

int main()
{
    IOS;
    //TEST{

 string a,b,res="-1";
 cin>>a>>b;
vector<string>str,sb,st,sbb;

 rep(i,a.length()){
 string str1=a.substr(0,i+1);
 string sss=a.substr(a.length()-i-1,a.length());
// cout<<str1<<" "<<sss<<endl;
 if(str1!=sss)continue;
 str.pb(str1);
 string str2=a.substr(i+1,a.length());
st.pb(str2);
 }
 rep(i,b.length()){
  string sb1=b.substr(b.length()-i-1,b.length());
  string sss=b.substr(0,i+1);
  if(sb1!=sss)continue;
 sb.pb(sb1);
  string sb2=b.substr(0,b.length()-i-1);
 sbb.pb(sb2);
 }
 bool l=0;
 rep(i,str.size()){
     if(l)break;
 for(int  j=0;j<sb.size();j++){
     if(string(sb[j]+st[i])==string(sbb[j]+str[i])){res=sbb[j]+str[i]; l=1;}
 }
 }
  if(a==b)res=a;
 cout<<res;
cout<<endl;
//}
    return 0;
}
Copy
Right into Two AlCoach
GNU G++17
0 ms
472 KB
Wrong Answer