QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#460593#8829. AibohphobiaQwertyPi#WA 1ms3408kbC++141.3kb2024-07-01 21:18:392024-07-01 21:18:40

Judging History

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

  • [2024-07-01 21:18:40]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3408kb
  • [2024-07-01 21:18:39]
  • 提交

answer

#include <bits/stdc++.h>
#define all(a) begin(a), end(a)
#define sz(a) (int) (a).size();
using namespace std;

void solve() {
    string s; cin >> s;
    map<char, int> M;
    for (auto c : s) {
        M[c]++;
    }

    if (M.size() == 1) {
        cout << "NO" << '\n';
        return;
    }
    
    if (M.size() == 2) {
        bool has_1 = false;
        for (auto [c, cc] : M) {
            if (cc == 1) has_1 = true;
        }
        
        if (!has_1) {
            cout << "NO" << '\n';
            return;
        }
        char fi = '\0';
        vector<char> C;
        for (auto [c, cc] : M) {
            C.push_back(c);
        }
        if (M[C[0]] > 1) swap(C[0], C[1]);
        cout << "YES" << '\n';
        for (auto c : C) {
            for (int j = 0; j < M[c]; j++) {
                cout << c;
            }
        }
        cout << '\n';
        return;
    }

    cout << "YES" << '\n';
    for (auto [c, cc] : M) {
        cout << c;
    }
    for (auto [c, cc] : M) {
        for (int  i = 1; i < cc; i++) {
            cout << c;
        }
    }
    cout << '\n';
}

int32_t main(){
#ifndef LOCAL
    cin.tie(0); cout.tie(0)->sync_with_stdio(false);
#endif
    int t; cin >> t;
    while (t--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3408kb

input:

5
a
sos
abba
icpc
tenet

output:

NO
YES
oss
NO
YES
cipc
YES
entet

result:

wrong answer Jury found the answer but participant didn't (test case 1)