QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#647284#8829. AibohphobiaAndevikingWA 0ms3828kbC++201.4kb2024-10-17 13:12:542024-10-17 13:12:57

Judging History

你现在查看的是最新测评结果

  • [2024-10-17 13:12:57]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3828kb
  • [2024-10-17 13:12:54]
  • 提交

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)