forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path2.java
More file actions
37 lines (30 loc) Β· 1.07 KB
/
2.java
File metadata and controls
37 lines (30 loc) Β· 1.07 KB
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
import java.util.*;
public class Main {
public static String str;
public static ArrayList<Character> result = new ArrayList<Character>();
public static int value = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
str = sc.next();
// λ¬Έμλ₯Ό νλμ© νμΈνλ©°
for (int i = 0; i < str.length(); i++) {
// μνλ²³μΈ κ²½μ° κ²°κ³Ό 리μ€νΈμ μ½μ
if (Character.isLetter(str.charAt(i))) {
result.add(str.charAt(i));
}
// μ«μλ λ°λ‘ λνκΈ°
else {
value += str.charAt(i) - '0';
}
}
// μνλ²³μ μ€λ¦μ°¨μμΌλ‘ μ λ ¬
Collections.sort(result);
// μνλ²³μ μ°¨λ‘λλ‘ μΆλ ₯
for (int i = 0; i < result.size(); i++) {
System.out.print(result.get(i));
}
// μ«μκ° νλλΌλ μ‘΄μ¬νλ κ²½μ° κ°μ₯ λ€μ μΆλ ₯
if (value != 0) System.out.print(value);
System.out.println();
}
}