Zoj problem set-1383 binary numbers

Source: Internet
Author: User

Time Limit: 2 seconds memory limit: 65536 KB

Given a positive integer N, print out 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 <= 10 ^ 6.

Output
The output shoshould consists of exactly D lines, one line for each data set.
Line I, 1 <= I <= D, shoshould contain increasing sequence of integers separated by single spaces-the positions of 1's in the binary representation of the I-th input number.

Sample Input

1
13

Sample output

0 2 3

Source:Central Europe 2001, practice

Note The control of spaces in the output format!

 
# Include <iostream>
Using NamespaceSTD;
 
IntMain ()
 
{
 
IntNums; CIN> Nums;
IntNumber;
 
While(Nums -- & CIN> Number)
 
{
 
IntJ = 0;
For(IntI = 0; number >>=1, I ++)
 
{
 
If(Number & 1> 0)
 
{
If(J! = 0)
 
Cout <" ";
 
Cout <I;
 
J ++;
 
}
}
 
Cout <Endl;
 
}
 
Return0;
 
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.