TOJ 1477. Binary Numbers

来源:互联网 发布:扫地机器人知乎 编辑:程序博客网 时间:2024/06/16 00:30
Given a positive integer n, find the positions of all 1's in its binary representation. The position of the least significant bit is 0.

Example
The positions of 1's in the binary representation of 13 are 0, 2, 3.

Task

Write a program which for each data set:

  • reads a positive integer n,
  • computes the positions of 1's in the binary representation of n,
  • writes the result.

Input

The first line of the input contains exactly one positive integer d equal to the number of data sets, 1 ≤d ≤ 10. The data sets follow.
Each data set consists of exactly one line containing exactly one integer n, 1 ≤n ≤ 106.

Output

The output should consists of exactly d lines, one line for each data set.
Line i, 1 ≤ id, should contain increasing sequence of integers separated by single spaces - the positions of 1's in the binary representation of thei-th input number.

Do not output any spaces in the end of a line.

Sample Input

113

Sample Output

0 2 3

#include<iostream>#include<cstring>using namespace std;int main(){int n,d;cin>>d;while(d--){cin>>n;//memset(a,0,sizeof(a));//int i=num;int i=0;while(n>1){   if(n%2==1)   cout<<i<<" ";   i++;   n=n/2;}cout<<i<<endl;}return 0;}


0 0
原创粉丝点击