-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExam37_Programers_level2_8.java
More file actions
54 lines (52 loc) · 1 KB
/
Copy pathExam37_Programers_level2_8.java
File metadata and controls
54 lines (52 loc) · 1 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
package algorithm;
public class Exam37_Programers_level2_8 {
//https://programmers.co.kr/learn/courses/30/lessons/12899
//규칙1. 3으로 나눠질경우 몫을 -1 함
//계속 반복
public String solution(int n) {
int val = 0;
StringBuffer sb = new StringBuffer();
while(n>0) {
val = n / 3;
if(n%3==0) {
val--;
sb.append(4);
}else{
sb.append(n%3);
}
n = val;
}
return sb.reverse().toString();
}
public static void main(String[] args) {
Exam_35 e = new Exam37_Programers_level2_8();
e.solution(60);
/*
* 7 21
* 8 22
* 9 24
* 10 41
* 11 42
* 12 44
* 13 111
* 14 112
* 15 114
* 16 121
* 17 122
* 18 124
* 19 141
* 20 142
* 21 144
* 22 211
* 1 2 4 11 12 14 21 22 24 41 42 44
*
* 3으로 나눈 나머지가 1이면 1
* 2이면 2
* 0이면 4
*
* 3...1 1
* 1...0 4
* 2
*/
}
}