QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#549665 | #8829. Aibohphobia | ucup-team4906# | WA | 0ms | 3856kb | C++20 | 1.1kb | 2024-09-06 19:29:40 | 2024-09-06 19:29:40 |
Judging History
answer
#include<bits/stdc++.h>
#define F(i, a, b) for(int i = a; i <= b; i ++)
using namespace std;
void sol() {
string s; cin >> s;
int n = s.size();
s = " " + s;
vector<int> cnt(26);
int tot = 0;
F(i, 1, n) {
int x = s[i] - 'a';
tot += ! cnt[x] ++;
}
// cout << tot << "!!\n";
if(n == 1) {
cout << "YES\n" << s[1] << "\n";
return;
}
if(tot == 1) {
cout << "NO\n";
return;
}
int ok = 1;
if(tot == 2) {
ok = 0;
F(i, 0, 25) if(cnt[i] == 1) ok = 1;
}
if(! ok) {
cout << "NO\n";
return;
}
cout << "YES\n";
F(i, 0, 25) if(cnt[i]) {
cnt[i] --;
cout << (char)(i + 'a');
}
F(i, 1, n - tot) {
F(j, 0, 25) if(cnt[j]) {
cout << (char)(j + 'a');
cnt[j] --;
break;
}
}
cout << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t; cin >> t;
F(i, 1, t) sol();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
input:
5 a sos abba icpc tenet
output:
YES a YES oss NO YES cipc YES entet
result:
ok Correct (5 test cases)
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3856kb
input:
18 qnx oooo tvttj zzzzz pvlne iijt hjhjj loo hh uq mgvgv ewwe iii kykk o mmumm aetvv xntl
output:
YES nqx NO YES jtvtt NO YES elnpv YES ijti NO YES loo NO YES qu YES gmvgv NO NO YES kykk YES o YES mummm YES aetvv YES lntx
result:
wrong answer Some prefix is a palindrome (test case 14)