-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDH_389481.java
More file actions
54 lines (40 loc) · 1.28 KB
/
DH_389481.java
File metadata and controls
54 lines (40 loc) · 1.28 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.Arrays;
/*
* 봉인된 주문
*/
public class DH_389481 {
static String solution(long n, String[] bans) {
// 사전순으로 정렬하기
Arrays.sort(bans, (o1, o2) -> {
if(o1.length() == o2.length()) return o1.compareTo(o2);
return o1.length() - o2.length();
});
// bans[i]의 순서를 확인하면서, n보다 작으면 n의 크기 늘려주기
for(String b: bans) {
long cnt = 0;
for(int i = 0; i < b.length(); i++) {
cnt += (b.charAt(i) - 'a' + 1) * (long) Math.pow(26, b.length() - (i + 1));
}
if(cnt <= n) n++;
}
// n번째 주문 찾기
StringBuilder sb = new StringBuilder();
// 26으로 계속 나누어주면서 맨 뒤에서부터 문자 채워주기
while(n > 0) {
long ch = n % 26;
n /= 26;
if(ch == 0) {
n--;
sb.insert(0, 'z');
} else {
sb.insert(0, (char) ('a' + ch - 1));
}
}
return sb.toString();
}
public static void main(String[] args) {
int n = 26 + 26;
String[] bans = new String[] {};
System.out.println(solution(n, bans));
}
}