QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#706787 | #8829. Aibohphobia | nsuDDDdd# | TL | 0ms | 3564kb | C++23 | 1.1kb | 2024-11-03 13:28:45 | 2024-11-03 13:28:45 |
Judging History
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;
}
Details
Tip: Click on the bar to expand more detailed information
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