-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMain.java
39 lines (29 loc) Β· 1.03 KB
/
Main.java
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
package String.P1213;
import java.io.*;
public class Main {
static int[] count = new int[26];
public static void main(String[] args) throws Exception {
System.setIn(new FileInputStream("src/String/P1213/input.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
count[c - 'A'] ++;
}
System.out.println(getPalindrome());
}
static String getPalindrome() {
StringBuilder sb = new StringBuilder();
String lastChar = "";
for (int i = 0; i < 26; i++) {
char c = (char) (i + 'A');
int iter = count[i] / 2;
while (iter-- > 0) sb.append(c);
if (count[i] % 2 == 1) {
if (!lastChar.equals("")) return "I'm Sorry Hansoo";
lastChar = String.valueOf(c);
}
}
return String.valueOf(sb) + sb.append(lastChar).reverse();
}
}