QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#706787#8829. AibohphobiansuDDDdd#TL 0ms3564kbC++231.1kb2024-11-03 13:28:452024-11-03 13:28:45

Judging History

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

  • [2024-11-03 13:28:45]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3564kb
  • [2024-11-03 13:28:45]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

void solve(){
    string s;cin>>s;
    int len=s.length();
    map<char,int>mp;
    for(auto &i:s){
        mp[i]++;
    }


    if(mp.size()==2){
        int f=0;
        for(auto[x,y]:mp){
            if(y<2){f=1;}
        }
        if(!f){cout<<"NO"<<endl;}
        else{
            cout<<"YES"<<endl;
            int num=0;
           for(char i='a';i<='z';i++){
               if(i>='z'){i='a';}
               if(num==len){break;}
               if(mp[i]>=1){
                   cout<<i;
                   mp[i]=max(0,mp[i]-1);
                   num++;
               }
           }cout<<endl;
        }
    }
    else{//YES
        cout<<"YES"<<endl;
        int num=0;
        for(char i='a';i<='z';i++){
            if(i>='z'){i='a';}
            if(num==len){break;}
            if(mp[i]>=1){
                cout<<i;
                mp[i]=max(0,mp[i]-1);
                num++;
            }
        }cout<<endl;
    }
}

signed main()
{
    int t;cin>>t;
    while(t--){
        solve();

    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3564kb

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
Time Limit Exceeded

input:

18
qnx
oooo
tvttj
zzzzz
pvlne
iijt
hjhjj
loo
hh
uq
mgvgv
ewwe
iii
kykk
o
mmumm
aetvv
xntl

output:

YES
nqx
YES
oooo
YES
jtvtt
YES

result: