QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#549673#8829. Aibohphobiaucup-team4906#WA 0ms3552kbC++201.3kb2024-09-06 19:33:382024-09-06 19:33:40

Judging History

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

  • [2024-09-06 19:33:40]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3552kb
  • [2024-09-06 19:33:38]
  • 提交

answer

#include<bits/stdc++.h>
#define F(i, a, b) for(int i = a; i <= b; i ++)

using namespace std;

void sol() {
    string s; cin >> s;
    int n = s.size();
    s = " " + s;
    vector<int> cnt(26);
    int tot = 0;
    F(i, 1, n) {
        int x = s[i] - 'a';
        tot += ! cnt[x] ++;
    }
    // cout << tot << "!!\n";
    if(n == 1) {
        cout << "YES\n" << s[1] << "\n";
        return;
    }
    if(tot == 1) {
        cout << "NO\n";
        return;
    }
    int ok = 1;
    if(tot == 2) {
        ok = 0;
        F(i, 0, 25) if(cnt[i] == 1) ok = i + 1;
        if(! ok) {
            cout << "NO\n";
            return;
        }
        cout << "YES\n";
        cout << (char)(ok - 1 + 'a');
        F(i, 0, 25) if(cnt[i] && i + 1 != ok) {
            F(j, 1, cnt[i]) cout << (char)(i + 'a');
        } 
        return;
    }
    
    cout << "YES\n";
    F(i, 0, 25) if(cnt[i]) {
        cnt[i] --;
        cout << (char)(i + 'a');
    } 
    F(i, 1, n - tot) {
        F(j, 0, 25) if(cnt[j]) {
            cout << (char)(j + 'a');
            cnt[j] --;
            break;
        }
    }
    cout << "\n";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t; cin >> t;
    F(i, 1, t) sol();
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3552kb

input:

5
a
sos
abba
icpc
tenet

output:

YES
a
YES
ossNO
YES
cipc
YES
entet

result:

wrong answer Not a permutation (test case 2)