Source Code
#include <iostream>
#include <algorithm>
#include <iterator>
#include <math.h>
#include <vector>
#include <set>
#include <map>
using namespace std;
vector<long long>v;
long long n;
int main() {
	string s1, s2, x1, x2, y;
	cin >> s1 >> s2;
	x1 = x2 = y = "";
	bool suf, pre;
	suf = pre = 0;
	for (int i = s1.size()-1; i > 0; i--) {
		x1 += s1[i];
		x2 = x1;
		reverse(x2.begin(), x2.end());
		if (s1.substr(0, s1.size() - i) == x2) {
			suf = 1;
			break;
		}
	}
	for (int i = 0; i < s2.size(); i++) {
		y += s2[i];
		if (s2.substr(s2.size() - i - 1, s2.size() - 1) == y) {
			pre = 1;
			break;
		}
	}
	if (pre && suf)cout << y + x2;
	else cout << -1;
	return 0;
}
Copy
Right into Two Sarah
GNU G++17
1 ms
600 KB
Wrong Answer