05-17 21:28
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Physical Scheme
- BFS
- Reference Type
- X.org
- OOP
- 리눅스
- Mac
- python
- 자바
- spring
- descriptive statistics
- Polymolphism
- Entity Set
- Entity
- literal
- External Scheme
- X윈도우
- systemd
- preprocessing
- Class
- Binary Search
- 리눅스 마스터 1급
- selenium
- dbms
- Unity
- 셀레니움
- Inheritance
- Java
- 백준
- Operator
Archives
- Today
- Total
Byeol Lo
N1052 - 물병 본문
import java.util.Scanner;
public class Main {
static final Scanner SC = new Scanner(System.in);
public static void main(String[] args) {
int n = SC.nextInt(), k = SC.nextInt(), result, cnt = 0, tmp = 0;
String binaryNumber = Integer.toBinaryString(n);
if(n <= k || binaryNumber.equals("1" + "0".repeat(binaryNumber.length() - 1))) {
result = 0;
} else {
for(int i=0; i<binaryNumber.length(); i++) {
if(binaryNumber.charAt(i) == '1') {
cnt++;
if(cnt == k) tmp = i;
}
}
if(cnt <= k) result = 0;
else {
result = (n &
Integer.parseInt("1".repeat(tmp + 1) + "0".repeat(binaryNumber.length() - tmp - 1), 2)) +
Integer.parseInt("1" + "0".repeat(binaryNumber.length() - tmp - 1), 2) - n;
}
}
System.out.print(result);
}
}
Comments