[백준, BOJ 3460] 이진수 (java)
Problem Solving/BOJ

[백준, BOJ 3460] 이진수 (java)

728x90

https://www.acmicpc.net/problem/3460

메모리: 14,016 KB , 시간: 96 ms

사용 알고리즘: 구현, 수학

728x90

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception{

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int T = Integer.parseInt(br.readLine());

        StringBuilder result = new StringBuilder();
        int n, idx;
        for (int tc = 0; tc < T; tc++) {
            n = Integer.parseInt(br.readLine());
            idx = 0;

            while(n > 0) {
                if((n & 1) == 1) result.append(idx).append(" ");
                n = n >> 1;
                idx++;
            }

            result.append("\n");
        }

        System.out.print(result);
    }
}
728x90