QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#761810 | #8829. Aibohphobia | Esouling | WA | 1ms | 3776kb | C++20 | 1.2kb | 2024-11-19 10:25:59 | 2024-11-19 10:25:59 |
Judging History
answer
#include <bits/stdc++.h>
void solve() {
std::string s;
std::cin >> s;
int n = s.size();
if (n == 1) {
std::cout << "YES\n";
std::cout << s << '\n';
return;
}
std::sort(s.begin(), s.end());
std::map<char, int> mp;
for (int i = 0; i < n; i ++) {
mp[s[i]] ++;
}
if (mp.size() == 1) {
std::cout << "NO\n";
} else if (mp.size() == 2) {
char ch = '!';
for (const auto &[c, cnt] : mp) {
if (cnt == 1) ch = c;
}
if (ch == '!') {
std::cout << "NO\n";
return;
}
std::cout << "YES\n";
std::cout << ch;
for (int i = 0; i < n; i ++) {
if (s[i] != ch) {
std::cout << s[i];
}
}
std::cout << '\n';
return;
}
std::cout << "YES\n";
for (auto &[c, cnt] : mp) {
std::cout << c;
cnt --;
}
for (auto &[c, cnt] : mp) {
while (cnt --) std::cout << c;
}
std::cout << '\n';
}
int main() {
int t;
std::cin >> t;
while (t --) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3776kb
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: 3540kb
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 oooo YES jtvtt NO YES zzzzz YES elnpv YES ijti NO YES loo NO YES hh YES uq YES gmvgv NO NO YES iii YES ykkk YES o YES ummmm YES aetvv YES lntx
result:
wrong answer Not a permutation (test case 3)