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 ≤ i ≤ d, 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
- TOJ 1477. Binary Numbers
- TOJ:2971. Rotating Numbers
- TOJ 2801. Binary Trees
- TOJ 1962.Skew Binary
- TOJ 3504 Repeatless Numbers / 深搜
- TOJ 1203.Factoring Large Numbers
- TOJ 2353.Reduced ID Numbers
- Binary Numbers
- Binary Numbers
- Binary Numbers
- Binary Numbers
- TOJ 2931 Raising Modulo Numbers 快速幂
- TOJ 2801.Binary Trees(二叉树后序转中序)
- hdu 1390 Binary Numbers
- zoj 1383 Binary Numbers
- zoj1383---------------------Binary Numbers
- HDU 1390 Binary Numbers
- ZOJ 1383 Binary Numbers
- Fork/Join Framework Tutorial: ForkJoinPool Example
- 《程序员面试宝典》部分字符串题目
- poj 3126 Prime Path 【暴力BFS】
- linux 学习笔记 后台进程运行程序
- Java1.7 SSL访问Https occur SSLProtocolException and CertificateException
- TOJ 1477. Binary Numbers
- openstack学习指南
- C++中_onexit()用法简述
- java二维码
- ireport中使用java进行pdf转化,jasper作为模板
- UVA 11582 Colossal Fibonacci Numbers!(打表+快速幂)
- hibernate 缓存
- TOMCAT内存优化配置
- mysql函数大全