forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPalindrome Reorder.cpp
57 lines (47 loc) · 1.05 KB
/
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
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
typedef long long ll;
//void subMain(){
//}
string solve(string str){
unordered_map<char, int> hmap;
for(int i = 0; i < str.length(); i++){
hmap[str[i]]++;
}
int oddcount = 0;
char oddchar;
for(auto x : hmap){
if(x.second %2 != 0){
oddcount++;
oddchar = x.first;
}
}
if(oddcount > 1 || oddcount==1 && str.length()%2 == 0)
return "NO SOLUTION";
string firsthalf = "", secondhalf = "";
for(auto x : hmap){
string s(x.second/2, x.first);
firsthalf = firsthalf + s;
secondhalf = s + secondhalf;
}
return (oddcount == 1) ?
(firsthalf + oddchar + secondhalf) :
(firsthalf + secondhalf);
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
/*ll t;
cin >> t;
while(t-- > 0){
subMain();
}*/
//subMain();
string s;
cin >> s;
cout << solve(s);
return 0;
}