-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindromeReorder.cpp
More file actions
46 lines (41 loc) · 818 Bytes
/
Copy pathPalindromeReorder.cpp
File metadata and controls
46 lines (41 loc) · 818 Bytes
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define int ll
string s;
map <char, int> mp;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> s;
for(int i = 0; i < s.size(); i++)
{
mp[s[i]]++;
}
int Cnt = 0;
for(auto i : mp) Cnt += (i.se % 2);
if(Cnt > 1)
{
cout << "NO SOLUTION";
return 0;
}
string res = "";
string thua = "";
for(auto i : mp)
{
if(i.se % 2 == 0)
{
for(int j = 1; j <= i.se / 2; j++) res += i.fi;
}
else
{
for(int j = 1; j <= i.se; j++) thua += i.fi;
}
}
string rres = res;
reverse(rres.begin(), rres.end());
cout << res << thua << rres;
}