Source Code
#include <iostream>
#include <algorithm>
#include<vector>
using namespace std;

int main(){
	string s,p;

	cin>>s>>p;
	int P = (int)p.size();
	int S = (int)s.size();

	for (int i=1;i<P;i++){
		// cout<<i<<endl;
		for(int j=1;j<=S;j++){
			if(p.substr(0,i)+s.substr(S-j,j) == p.substr(P-i,i)+s.substr(0,j)){
				cout<<p.substr(0,i)+s.substr(S-j,j)<<endl;
				return 0 ;
			}
		}
	}

	cout<<-1<<endl;
}
Copy
Right into Two Rimawi
GNU G++17
0 ms
508 KB
Wrong Answer