您的位置:首页 > 其它

hdu 1390 Binary Numbers

2011-09-15 12:15 281 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1390

/*
2011-9-15
author:BearFly1990
*/
package acm.hdu.tests;

import java.io.BufferedInputStream;
import java.util.Scanner;

public class HDU_1390 {
public static void main(String[] args) {
Scanner in = new Scanner(new BufferedInputStream(System.in));
int t = in.nextInt();

while(t-- > 0){
int n = in.nextInt();
String str = Integer.toBinaryString(n);
int[] arry = new int[str.length()];
int index = 0;
//System.out.println(str);
for(int i = 0 ,j = str.length()-1; j >= 0 ; i++,j--){
if(str.charAt(j) == '1'){
arry[index++] = i;
}
}
System.out.print(arry[0]);
for(int i = 1 ; i < index; i++){
System.out.print(" "+arry[i]);
}
System.out.println();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: