-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmentob11005_2.java
More file actions
47 lines (38 loc) ยท 1.25 KB
/
Copy pathmentob11005_2.java
File metadata and controls
47 lines (38 loc) ยท 1.25 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
package backjoon;
import java.util.Scanner;
//๋ฉํ ๋์ด ํ์ดํด์ฃผ์ ์ฝ๋. ๋ฉ์๋๋ฅผ ๋๋ ์ ๊ฐ๊ฐ์ ์ญํ ์ ํ ์ ์๊ฒ๋ ๊ตฌํํ๋ค.
public class mentob11005_2 {
public static void main(String[] args) {
new mentob11005_2().solve();
}
private void solve() {
Scanner sc = new Scanner(System.in);
String[] input = sc.nextLine().split(" ");
int base10 = Integer.parseInt(input[0], 10);
int base = Integer.parseInt(input[1], 10);
String result = changeBaseN(base10, base);
System.out.println(result);
}
private String changeBaseN(int base10, int base) {
String[] nBase = makeNBase(base);
String result = "";
while (base10 >= base) {
int num = base10 % base;
base10 = base10 / base;
result = nBase[num] + result;
}
result = nBase[base10] + result;
return result;
}
private String[] makeNBase(int base) {
String[] nBase = new String[base];
for (int i = 0; i < base; i++) {
if (i < 10) {
nBase[i] = i + "";
} else {
nBase[i] = (char)('A' + (i - 10)) + "";
}
}
return nBase;
}
}