Source Code
#include <iostream>

using namespace std;

int main()
{
    string s,c;
    cin>>s>>c;
    int n=s.size();
    int m=c.size();
    int g=n+m;
    int v=g/2;
    for(int i=-1;i<n;i++)
    {
        int ii=i;
        if(ii+1+m<n-ii-1)
            continue;
        ii=m+ii+1;
        string ss="",cc="";

        for(int j=0;j<m-(ii-v);j++)
            cc+=c[j];
        for(int j=0;j<=i;j++)
            cc+=s[j];
        for(int j=m-(ii-v);j<m;j++)
        {
            ss+=c[j];
        }
        for(int j=i+1;j<n;j++)
        {
            ss+=s[j];
        }

       if(ss==cc)
       {
           cout<<ss<<endl;
           return 0;
       }
    }
    cout<<-1<<endl;

}


Copy
Right into Two CR7
GNU G++17
204 ms
936 KB
Accepted