-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path1755.cpp
43 lines (42 loc) · 925 Bytes
/
1755.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
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int cnt[26] = {};
string s; cin >> s;
for (char &c: s) {
++cnt[c - 'A'];
}
int cnt_odd = 0, ind_odd = -1;
for (int i = 0; i < 26; ++i) {
if (cnt[i] & 1) {
++cnt_odd;
ind_odd = i;
}
}
if (cnt_odd > 1) {
cout << "NO SOLUTION\n";
} else {
for (int i = 0; i < 26; ++i) {
if (cnt[i] > 0 && i != ind_odd) {
for (int j = 1; j <= cnt[i] / 2; ++j) {
cout << (char)('A' + i);
}
}
}
if (ind_odd != -1) {
for (int j = 1; j <= cnt[ind_odd]; ++j) {
cout << (char)('A' + ind_odd);
}
}
for (int i = 25; i >= 0; --i) {
if (cnt[i] > 0 && i != ind_odd) {
for (int j = 1; j <= cnt[i] / 2; ++j) {
cout << (char)('A' + i);
}
}
}
cout << "\n";
}
return 0;
}