-
Notifications
You must be signed in to change notification settings - Fork 0
/
Palindrome_Reorder.cpp
108 lines (83 loc) · 1.44 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
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
#include <bits/stdc++.h>
using namespace std;
void solve()
{
int a, b;
cin >> a >> b;
// 4 5
// 3 3
// 1 2
// 0 0
// 10 20
// 9
// 4 4
// 2 3
// 1 1
// NO
//
if (a > 2 * b || b > 2 * a)
{
cout << "NO\n";
return;
}
if ((a + b) % 3 == 0)
cout << "YES\n";
else
cout << "NO\n";
}
string rep(char ch, int x)
{
string s = "";
for (int i = 0; i < x; i++)
s += ch;
return s;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string x;
cin >> x;
map<char, int> mp;
for (int i = 0; i < 26; i++)
{
mp['A' + i] = 0;
}
for (auto ch : x)
mp[ch]++;
int co = 0;
int r = 0;
char ch = '1';
for (auto i : mp)
{
if (i.second % 2 != 0)
{
co++;
ch = i.first;
r = i.second;
}
if (co > 1)
{
cout << "NO SOLUTION" << '\n';
return 0;
}
}
string res = "";
for (auto i : mp)
{
if (i.second % 2 == 1)
continue;
res += rep(i.first, i.second / 2);
}
cout << res;
if(ch != '1') {
for(int i = 0; i < r; i++)
{
cout << ch;
}
}
reverse(res.begin(), res.end());
cout << res << '\n';
return 0;
}