QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#761810#8829. AibohphobiaEsoulingWA 1ms3776kbC++201.2kb2024-11-19 10:25:592024-11-19 10:25:59

Judging History

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

  • [2024-11-19 10:25:59]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3776kb
  • [2024-11-19 10:25:59]
  • 提交

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)