-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathJW_17686.java
More file actions
31 lines (29 loc) Β· 1.13 KB
/
JW_17686.java
File metadata and controls
31 lines (29 loc) Β· 1.13 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
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class JW_17686 {
public String[] solution(String[] files) {
// μ κ·ννμ
String regex = "^([^0-9]+)([0-9]{1,5}).*$";
Pattern pattern = Pattern.compile(regex);
String[][] strArr = new String[files.length][3];
for (int i = 0; i < files.length; i++) {
String fileName = files[i];
Matcher matcher = pattern.matcher(fileName);
// μ κ·ννμμ μ΄μ©νμ¬ κ·Έλ£Ήν
if (matcher.find()) {
String header = matcher.group(1).toLowerCase();
String number = matcher.group(2);
strArr[i] = new String[] { fileName, header, number };
}
}
// 쑰건μ λ§κ² μ λ ¬
Arrays.sort(strArr, (s1, s2) -> !s1[1].equals(s2[1]) ? s1[1].compareTo(s2[1])
: Integer.parseInt(s1[2]) - Integer.parseInt(s2[2]));
String[] answer = new String[files.length];
for (int i = 0; i < files.length; i++) {
answer[i] = strArr[i][0];
}
return answer;
}
}