为什么判 NOT POSSIBLE 会挂几个点
查看原帖
为什么判 NOT POSSIBLE 会挂几个点
482610
Mortidesperatslav楼主2024/6/1 14:38
#include<bits/stdc++.h>
using namespace std;
int n, len, js, ans;
string s, qz = " ", hz = " ";
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin >> n;
	if (n % 2 == 0){
		cout << "NOT POSSIBLE";
		return 0;
	}
	cin >> s;
	s = " " + s;
	len = n / 2;
	js = 0;
	for (int i = 1; i <= len; i++)
		qz += s[i];
	for (int i = len + 2; i <= n; i++)
		hz += s[i]; 
	int pos = 1, ppos = len + 1;
	while (pos <= len && ppos <= n){
		if (s[pos] != s[ppos])
			ppos++, js++;
		pos++, ppos++;	
	}
	pos--, ppos--;
	if (pos == len && ppos == n && js == 1)
		ans++;
	else if (pos == len && ppos == n - 1 && js == 0)
		ans++;
	js = 0;
	pos = len + 2, ppos = 1;
	while (pos <= n && ppos <= len + 1){
		if (s[pos] != s[ppos])
			ppos++, js++;
		pos++, ppos++;
	}
	pos--, ppos--;
	if (pos == n && ppos == len + 1 && js == 1)
		ans += 2;
	else if (pos == n && ppos == len && js == 0)
		ans += 2;
	if (hz == qz && ans > 2)
		ans -= 2;
	if (ans == 0)
		cout << "NOT POSSIBLE";
	else if (ans == 3)
		cout << "NOT UNIQUE";
	else if (ans == 1)
		for (int i = 1; i <= len; i++)
			cout << s[i];
	else
		for (int i = len + 2; i <= n; i++)
			cout << s[i];
}
2024/6/1 14:38
加载中...