QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#549673 | #8829. Aibohphobia | ucup-team4906# | WA | 0ms | 3552kb | C++20 | 1.3kb | 2024-09-06 19:33:38 | 2024-09-06 19:33: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 = i + 1;
if(! ok) {
cout << "NO\n";
return;
}
cout << "YES\n";
cout << (char)(ok - 1 + 'a');
F(i, 0, 25) if(cnt[i] && i + 1 != ok) {
F(j, 1, cnt[i]) cout << (char)(i + 'a');
}
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: 0
Wrong Answer
time: 0ms
memory: 3552kb
input:
5 a sos abba icpc tenet
output:
YES a YES ossNO YES cipc YES entet
result:
wrong answer Not a permutation (test case 2)