QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#647284 | #8829. Aibohphobia | Andeviking | WA | 0ms | 3828kb | C++20 | 1.4kb | 2024-10-17 13:12:54 | 2024-10-17 13:12:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define range(x) (x).begin(), (x).end()
const int dir[][2] = {1, 0, -1, 0, 0, 1, 0, -1};
void solve()
{
string s;
cin >> s;
vector<int> cnt(26);
int n = s.size();
int sz = 0;
for (const auto &c : s)
cnt[c - 'a']++;
for (int i = 0; i < 26; ++i)
sz += bool(cnt[i]);
if (s.size() == 1) {
cout << "YES\n";
cout << s << '\n';
}
else if (sz == 1)
cout << "NO\n";
else if (n == 2 || n == 3) {
cout << "YES\n";
if (n == 2)
cout << s << '\n';
else {
sort(range(s));
if (s[0] == s[1])
reverse(range(s));
cout << s << '\n';
}
}
else if (sz == 2)
cout << "NO\n";
else {
cout << "YES\n";
for (int i = 0; i < 26; ++i)
if (cnt[i]) {
cnt[i]--;
cout << char(i + 'a');
}
for (int i = 0; i < 26; ++i)
if (cnt[i]) {
while (cnt[i]) {
cout << char(i + 'a');
cnt[i]--;
}
}
cout << '\n';
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3828kb
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: 3552kb
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 uq YES gmvgv NO NO NO YES o NO YES aetvv YES lntx
result:
wrong answer Jury found the answer but participant didn't (test case 14)