You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.4 KiB
C++
51 lines
1.4 KiB
C++
#define _CRT_SECURE_NO_WARNINGS
|
|
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
|
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
char s[150], s2[150];
|
|
int cnt[255];
|
|
int main()
|
|
{
|
|
int n;
|
|
scanf("%d", &n);
|
|
while (n--)
|
|
{
|
|
scanf("%s", s);
|
|
int len = strlen(s);
|
|
memset(cnt, 0, sizeof cnt);
|
|
for (int i = 0; i < len; i++) cnt[s[i]]++;
|
|
bool flag = true;
|
|
int cc = 0;
|
|
for (char ch = 'a'; ch <= 'z'; ch += 2)
|
|
while (cnt[ch]--) s2[cc++] = ch;
|
|
for (char ch = 'b'; ch <= 'z'; ch += 2)
|
|
while (cnt[ch]--) s2[cc++] = ch;
|
|
s2[len] = 0;
|
|
for (int i = 1; i < len; i++)
|
|
if (abs(s2[i] - s2[i - 1]) == 1)
|
|
flag = false;
|
|
if (flag)
|
|
puts(s2);
|
|
else
|
|
{
|
|
memset(cnt, 0, sizeof cnt);
|
|
for (int i = 0; i < len; i++) cnt[s[i]]++;
|
|
flag = true;
|
|
cc = 0;
|
|
for (char ch = 'b'; ch <= 'z'; ch += 2)
|
|
while (cnt[ch]--) s2[cc++] = ch;
|
|
for (char ch = 'a'; ch <= 'z'; ch += 2)
|
|
while (cnt[ch]--) s2[cc++] = ch;
|
|
s2[len] = 0;
|
|
for (int i = 1; i < len; i++)
|
|
if (abs(s2[i] - s2[i - 1]) == 1)
|
|
flag = false;
|
|
if (flag)
|
|
puts(s2);
|
|
else
|
|
puts("No answer");
|
|
}
|
|
}
|
|
return 0;
|
|
}
|