您的位置:首页 > 其它

杭电Hdu 1390 Binary Numbers

2013-01-06 16:38 337 查看
import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class Hdu1390 {

 static List<Integer> list = new ArrayList<Integer>();

 public static void main(String[] args) {

  Scanner sc = new Scanner(System.in);

  int n = sc.nextInt();

  for (int i = 0; i < n; i++) {

   int m = sc.nextInt();

   binary(m);

   boolean t = false;

   for (int j = 0; j < list.size(); j++) {

    if (list.get(j) == 1) {

     if (t) {

      System.out.print(" ");

     }

     System.out.print(j);

     t = true;

    }

   }

   System.out.println();

   list.clear();      //注意每次要清空

  }

 }

 static void binary(int x) {

  int a = 0;

  while (x != 0) {

   a = x % 2;

   x = x / 2;

   list.add(a);

  }

 }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: