-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCSES Palindrome_Reorder.cpp
122 lines (100 loc) · 2.4 KB
/
CSES Palindrome_Reorder.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include<bits/stdc++.h>
using namespace std;
using d = int;
using ll = long long;
using ud = unsigned int;
using ull = unsigned long long;
using lf = double;
using llf = long double;
using ch = char;
using st = string;
using bl = bool;
#define ci cin
#define co cout
#define fi( x, n ) for( d i = x; i < n; i++ )
#define fj( x, n ) for( d j = x; j < n; j++ )
#define fin( x, n ) for( d i = x; i <= n; i++ )
#define fjn( x, n ) for( d j = x; j <= n; j++ )
#define wh while
#define w( n ) while( n-- )
#define vd vector<d>
#define vll vector<ll>
#define vlf vector<lf>
#define vc vector<ch>
#define vs vector<st>
#define sd set<d>
#define sll set<ll>
#define slf set<lf>
#define sc set<ch>
#define ss set<st>
#define sz(x) x.size()
#define st(x) sort( x.begin(), x.end() )
#define cou(x, y) count( x.begin(), x.end(), y )
#define in insert
#define ct count
#define fd find
#define pb push_back
#define er erase
#define bg begin
#define np next_permutation
#define el endl
#define en end
d main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
cin>>s;
int f[26]={0};
for(int i=0;i<s.size();i++)
{
f[s[i]-'A']++;
}
int count=0;
for(int i=0;i<26;i++)
{
if(f[i]%2!=0)
count++;
}
if(count>1)
cout<<"NO SOLUTION"<<endl;
else
{
vector<char>v1,v2;
for(int i=0;i<26;i++)
{
if(f[i]%2!=0)
{
while(f[i]--)
{
v2.push_back(i+65);
}
}
else if(f[i]>0&&f[i]%2==0)
{
int x=f[i]/2;
while(x--)
{
v1.push_back(i+65);
}
}
}
for(int i=0;i<v1.size();i++)
{
cout<<v1[i];
}
for(int i=0;i<v2.size();i++)
{
cout<<v2[i];
}
for(int i=v1.size()-1;i>=0;i--)
{
cout<<v1[i];
}
}
#ifndef ONLINE_JUDGE
cerr <<el<< "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
#endif
return 0;
}