Skip to content

Commit cbcdaaf

Browse files
authored
[20250807] BOJ / G5 / 4와 7 / 이종환
1 parent 2623d06 commit cbcdaaf

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

0224LJH/202508/7 BOJ 4와 7.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
```java
2+
import java.io.BufferedReader;
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
import java.util.*;
6+
7+
8+
public class Main {
9+
10+
static int target;
11+
static List<Integer> list = new ArrayList<>();
12+
13+
14+
public static void main(String[] args) throws IOException {
15+
init();
16+
process();
17+
print();
18+
}
19+
20+
private static void init() throws IOException {
21+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
22+
target = Integer.parseInt(br.readLine());
23+
}
24+
25+
private static void process() throws IOException {
26+
27+
int pos = 1;
28+
29+
while ( target > 0){
30+
int pre = 1 << (pos-1);
31+
int cur = 1 << pos;
32+
33+
if ( (target&pre) != 0){
34+
target -= pre;
35+
list.add(4);
36+
}else{
37+
target -= cur;
38+
list.add(7);
39+
}
40+
pos++;
41+
42+
43+
}
44+
}
45+
46+
47+
private static void print() {
48+
for (int i = list.size()-1; i >= 0; i--){
49+
System.out.print(list.get(i));
50+
}
51+
}
52+
}
53+
```

0 commit comments

Comments
 (0)