-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1755.cpp
More file actions
46 lines (44 loc) · 977 Bytes
/
1755.cpp
File metadata and controls
46 lines (44 loc) · 977 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 <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main()
{
string s;
cin >> s;
int n = s.size();
vector<int> v(26);
for (int i = 0; i < n; i++) {
v[s[i] - 'A']++;
}
int odd = 0;
for (int i = 0; i < 26; i++) {
if (v[i] % 2 == 1) {
odd++;
}
}
if (odd > 1) {
cout << "NO SOLUTION" << endl;
} else {
string t;
for (int i = 0; i < 26; i++) {
if (v[i] % 2 == 0) {
for (int j = 0; j < v[i] / 2; j++) {
t += (char)('A' + i);
}
}
}
cout << t;
for (int i = 0; i < 26; i++) {
if (v[i] % 2 == 1) {
for (int j = 0; j < v[i]; j++) {
cout << (char)('A' + i);
}
}
}
reverse(t.begin(), t.end());
cout << t << endl;
}
return 0;
}