QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#458280 | #8829. Aibohphobia | ucup-team3608# | TL | 0ms | 0kb | C++17 | 1.3kb | 2024-06-29 16:30:55 | 2024-06-29 16:30:57 |
answer
#include"bits/stdc++.h"
using lint = int64_t;
using namespace std;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
int t; cin>>t;
while(t--){
string s; cin>>s;
const int n = s.size();
if(n == 1){
cout<<"YES\n";
cout<<s<<"\n";
continue;
}
vector<int> cnt(26);
for(char c: s)
cnt[c-'a']++;
int small = 0;
for(int i = 0; i < 26; i++){
if((cnt[small] == 0 && cnt[i] != 0) || cnt[i] < cnt[small])
small = i;
}
string ans;
ans += 'a' + small;
cnt[small] --;
for(int i = 0; i < 26; i++){
if(i == small) continue;
while(cnt[i] != 0){
ans += char('a' + i);
cnt[i]--;
}
}
if(cnt[small]){
ans += 'a' + small;
cnt[small] --;
string t = ans;
reverse(t.begin(), t.end());
if(ans == t){
cout<< "NO\n";
continue;
}
}
while(cnt[small] != 0){
ans += char('a' + small);
cnt[small]--;
}
cout<< "YES\n";
cout<<ans<<"\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
5 a sos abba icpc tenet