65分求条
查看原帖
65分求条
995934
fkxr楼主2024/10/4 09:58
#include <bits/stdc++.h>
using namespace std;
#define int long long

bool ok(string s, string b) {
	int op = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != b[i + op]) {
			if (op == 0) {
				op = 1;
			} else {
				return 0;
			}
		}
	}
	return 1;
}

signed main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	if (n % 2 == 0) {
		cout << "NOT POSSIBLE";
		return 0;
	}/*
	bool okk = 1;
	for (int i = s.size() / 2 + 1; i < s.size(); i++) {
		if (s[i] != s[i - s.size() / 2 - 1]) {
			okk = 0;
			break;
		}
	}
	if (okk) {
		for (int i = 0; i < s.size() / 2; i++) {
			cout << s[i];
		}
		return 0;
	}*/
	string ss = s;
	string a = ss.substr(0, n / 2);
	string b = ss.erase(0, n / 2);
	bool ok1 = ok(a, b);
	string aa = s.substr(0, n / 2 + 1);
	string bb = s.erase(0, n / 2 + 1);
//	cout << aa << " " << bb;
	bool ok2 = ok(bb, aa);
	if (ok1 && ok2) {
		if (a != bb)
			cout << "NOT UNIQUE";
		else
			cout << a;
	} else if (!(ok1 || ok2)) {
		cout << "NOT POSSIBLE";
	} else {
		if (ok1) {
			cout << a;
		} else {
			cout << bb;
		}
	}
	return 0;
}
2024/10/4 09:58
加载中...