QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#577535 | #8829. Aibohphobia | Ycfhnnd | WA | 0ms | 3552kb | C++23 | 2.2kb | 2024-09-20 12:33:25 | 2024-09-20 12:33:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve(){
string s;
cin >> s;
int n = s.size();
if (n == 1){
cout << "YES\n" << s << "\n";
}else if (n == 2){
if (s[0] == s[1]){
cout << "NO\n";
}else{
cout << "YES\n" << s << "\n";
}
}else if(n == 3){
if (s[0] == s[1] and s[1] == s[2]){
cout << "NO\n";
}else{
cout << "YES\n";
sort(s.begin(), s.end());
if (s[0] == s[1]) swap(s[0], s[2]);
cout << s << "\n";
}
}else{
vector<int>cnt(26);
int c1 = 0;
for (auto c : s){
++cnt[c - 'a'];
if(cnt[c - 'a'] == 1){
c1 ++;
}
}
if (c1 == 1){
cout << "NO\n";
}else if(c1 == 2){
bool ok = false;
for (int i = 0;i < 26;i ++){
if (cnt[i] == 1){
ok = true;
}
}
if (!ok){
cout << "NO\n";
}else{
for (int i = 0;i < 26;i ++){
if (cnt[i] == 1){
cout << char('a' + i);
cnt[i] -= 1;
}
}
for (int i = 0;i < 26;i ++){
while(cnt[i]){
cout << char('a' + i);
cnt[i] -= 1;
}
}
cout << "\n";
}
}else{
cout << "YES\n";
for (int i = 0;i < 26;i ++){
if (cnt[i]){
cout << char('a' + i);
cnt[i] --;
}
}
for (int i = 0;i < 26;i ++){
while (cnt[i]){
cout << char('a' + i);
cnt[i] --;
}
}
cout << "\n";
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
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: 3552kb
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
Wrong Answer
time: 0ms
memory: 3532kb
input:
18 qnx oooo tvttj zzzzz pvlne iijt hjhjj loo hh uq mgvgv ewwe iii kykk o mmumm aetvv xntl
output:
YES nqx NO YES jtvtt NO YES elnpv YES ijti NO YES loo NO YES uq YES gmvgv NO NO ykkk YES o ummmm YES aetvv YES lntx
result:
wrong answer Token parameter [name=yes/no] equals to "ykkk", doesn't correspond to pattern "[yY][eE][sS]|[nN][oO]" (test case 14)