Skip to content

Commit 3d09166

Browse files
committed
BOJ_2885 : 초콜릿 식사
1 parent c4b00a9 commit 3d09166

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

week1/BOJ_2885(초콜릿 식사).java

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.io.*;
2+
3+
public class Main {
4+
5+
public static void main(String[] args) throws IOException {
6+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
int K = Integer.parseInt(br.readLine());
8+
int square = 1;
9+
while(square < K) {
10+
square *= 2;
11+
if(square == K) {
12+
System.out.println(square + " 0");
13+
return;
14+
}
15+
}
16+
int count = 0;
17+
int num = square;
18+
while(K >= 1) {
19+
num /= 2;
20+
if(num <= K) {
21+
K -= num;
22+
}
23+
count++;
24+
}
25+
System.out.println(square + " " + count);
26+
}
27+
}

0 commit comments

Comments
 (0)