Status ¶
Problem | 2453 | User | talin0528 |
Memory | 3656K | Time | 375MS |
Language | Java | Result | Accepted |
Idea ¶
bit 가 , 10 -> 2 변 배 다ㅠㅠ(끝내고 다 반대로..;ㅁ;..런 !)
1란 를 때 그 가 0면 1 로 보내고, 1면 맨 끝로 보내는...
ex)
0010 0000 -> 0100 0000
0011 1100 -> 0100 0111
1란 를 때 그 가 0면 1 로 보내고, 1면 맨 끝로 보내는...
ex)
0010 0000 -> 0100 0000
0011 1100 -> 0100 0111
Source Code ¶
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNextInt()){ int i = sc.nextInt(); if(i == 0) break; printJ(i); } } private static void printJ(int i){ int [] bin = binI(i); int num = 0, count=0; while(num<bin.length-1){ if(bin[num] == 1){ if(bin[num+1] == 0){ bin[num+1] = 1; bin[num] = 0; break; }else{ bin[num] = 0; bin[count++] = 1; } } num++; } int result = 0; for(int k=0; k<bin.length;k++){ result += bin[k]*Math.pow(2,k); } System.out.println(result); } private static int [] binI(int i){ int [] temp = new int [21]; int num = 0; while(i>0){ temp[num++] = i%2; i = i/2; } return temp; } }
Trial and error ¶
- Compile error
- 래 "Main"로 다. 깜 poj 같:)
- 래 "Main"로 다. 깜 poj 같:)
- Runtime error
- printJ 내 while(num
num+1가 index bound of exception 났다.
- printJ 내 while(num
- Wrong answer
- 2^20 = 1048576 로 1000000보다 까 배 기를 20로 는데, 1과 0 기면 보다 더 는 경를 고려 못다. 그 결과 1~1000000 4개 가 맨 1 려 가 게 력된! ;ㅅ; 뜻 보길래 맞 뻘 많 ㅋㅋ poj는 가 ! 내가 바보 ㅠㅠ
- 2^20 = 1048576 로 1000000보다 까 배 기를 20로 는데, 1과 0 기면 보다 더 는 경를 고려 못다. 그 결과 1~1000000 4개 가 맨 1 려 가 게 력된! ;ㅅ; 뜻 보길래 맞 뻘 많 ㅋㅋ poj는 가 ! 내가 바보 ㅠㅠ
I | 기대 값 | 값 |
524288 | 1048576 | 524288 |
786432 | 1048577 | 524289 |
917504 | 1048579 | 524291 |
983040 | 1048583 | 524295 |
- 가 다다 되 10를 2로 기려고 다가 그게 매 렵다는 깨달...; 배로 는 방법 군. -김