-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome Reorder.cpp
More file actions
73 lines (72 loc) · 1.69 KB
/
Copy pathPalindrome Reorder.cpp
File metadata and controls
73 lines (72 loc) · 1.69 KB
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
#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define all(v) (v).begin(), (v).end()
#define fl fflush(stdout)
int mod = 1e9 + 7;
void solve() {
string s; cin >> s;
map<char, int> alpha;
int n = s.length();
string ans = s;
for (int i = 0; i < n; i++) {
alpha[s[i]]++;
}
int cnt = 0;
char oddi;
for (auto x : alpha) {
if (x.ss % 2 != 0) {
cnt++;
oddi = x.ff;
}
} int k = 0;
if (cnt > 1) {
cout << "NO SOLUTION";
return;
}
else {
for (auto x : alpha) {
if (x.ss % 2 == 0) {
for (int j = 0; j < (x.ss / 2); j++) {
ans[k] = x.ff;
ans[n - k - 1] = x.ff;
k++;
}
}
}
}
if (cnt == 1)
for (int i = 0; i < alpha[oddi]; i++) {
ans[i + k] = oddi;
}
cout << ans;
}
signed main() {
auto start = high_resolution_clock::now();
IOS;
int t = 1;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r" , stdin);
freopen("output.txt", "w", stdout);
#endif
// cin >> t;
int i = 1;
while (t--) {
// cout << "CASE #" << i << ": ";
solve();
cout << endl;
i++;
}
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
cerr << "Time taken:" << duration.count() / 1000000.0 << " seconds" << "\n";
return 0;
}