-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1213.c
54 lines (46 loc) · 991 Bytes
/
1213.c
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
//
//
#include <stdio.h>
#include <ctype.h>
#define N 50
#define RANGE 'Z' - 'A' + 1
int main(void)
{
int bullets[RANGE] = {0};
int ammo = 0;
char pal[N] = {0};
char ch;
while ((ch = getchar()) != '\n') {
if (isalpha(ch)) {
bullets[ch - 'A']++;
ammo++;
}
}
int j = 0;
char middle;
int countdown = 1;
for (int i = 0; i < RANGE; ++i) {
while (bullets[i] >= 2) {
pal[j] = i + 'A';
pal[ammo - j - 1] = i + 'A';
bullets[i] -= 2;
j++;
}
if (bullets[i] == 1) {
countdown--;
if (ammo % 2 == 0 || countdown < 0) {
printf("I'm Sorry Hansoo\n");
return 0;
}
else {
middle = i + 'A';
bullets[i]--;
}
}
}
if (ammo % 2) {
pal[j] = middle;
}
printf(pal);
return 0;
}