-
Notifications
You must be signed in to change notification settings - Fork 0
/
B.cpp
91 lines (90 loc) · 2.11 KB
/
B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
fastio;
int t,i,n,j;
string s;
cin>>t;
while(t--)
{
cin>>s;
n=s.size();
vector<char> odd,even;
map<char,int> mp;
for(i=0;i<n;i++)
{
if((s[i]-'a')%2==0)
{
if(mp[s[i]]==0)
odd.push_back(s[i]);
mp[s[i]]++;
}
else
{
if(mp[s[i]]==0)
even.push_back(s[i]);
mp[s[i]]++;
}
}
sort(odd.begin(),odd.end());
sort(even.begin(),even.end());
if(even.size()==0)
{
for(i=0;i<odd.size();i++)
{
for(j=0;j<mp[odd[i]];j++)
cout<<odd[i];
}
cout<<"\n";
}
else if(odd.size()==0)
{
for(i=0;i<even.size();i++)
{
for(j=0;j<mp[even[i]];j++)
cout<<even[i];
}
cout<<"\n";
}
else if(abs(odd[odd.size()-1]-even[0])==1)
{
if(abs(even[even.size()-1]-odd[0])==1)
{
cout<<"No answer\n";
continue;
}
else
{
for(i=0; i<even.size(); i++)
{
for(j=0; j<mp[even[i]]; j++)
cout<<even[i];
}
for(i=0; i<odd.size(); i++)
{
for(j=0; j<mp[odd[i]]; j++)
cout<<odd[i];
}
cout<<"\n";
}
}
else
{
for(i=0;i<odd.size();i++)
{
for(j=0;j<mp[odd[i]];j++)
cout<<odd[i];
}
for(i=0;i<even.size();i++)
{
for(j=0;j<mp[even[i]];j++)
cout<<even[i];
}
cout<<"\n";
}
}
return 0;
}