-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1213(1).cpp
More file actions
43 lines (41 loc) · 764 Bytes
/
1213(1).cpp
File metadata and controls
43 lines (41 loc) · 764 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
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string S, ans = "", rev = "";
int alpha[26];
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> S;
for (int i = 0; i < S.size(); i++) {
alpha[S[i] - 'A']++;
}
int flag = 0; // flag : 0 or 1 => ok
string mid = "";
for (int i = 0; i < 26; i++) {
if (alpha[i] % 2 != 0) {
flag++;
mid = 'A' + i;
}
}
if (flag > 1) {
cout << "I'm Sorry Hansoo";
}
else {
for (int i = 0; i < 26; i++) {
if (alpha[i] != 0) {
for (int j = 0; j < alpha[i] / 2; j++) {
ans += char('A' + i);
}
}
}
rev = ans;
reverse(rev.begin(), rev.end());
if (flag == 1) {
ans += mid;
}
ans += rev;
cout << ans;
}
return 0;
}