HDU 1390 Binary Numbers
来源:互联网 发布:windows ab 压力测试 编辑:程序博客网 时间:2024/05/16 14:19
Binary Numbers
Problem Description
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.
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.
Each data set consists of exactly one line containing exactly one integer n, 1 <= n <= 10^6.
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 the i-th input number.
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 the i-th input number.
Sample Input
113
Sample Output
0 2 3
题意:给一个数,把它二进制所有的1的位置按顺序输出来。
其实不用转换二进制,直接位运算,因为位运算本来就是在二进制基础上操作的,左右移动去确定最后一位的值。
#include<stdio.h>#include<string.h>int main(){ int t,n,i,j; int a[100]; scanf("%d",&t); while(t--) { scanf("%d",&n); int e=0,f=0; while(n) { if(n>>1<<1!=n) { if(!f) { printf("%d",e); f=1; } else printf(" %d",e); } n>>=1; e++; } printf("\n"); } return 0;}
2 0
- hdu 1390 Binary Numbers
- HDU 1390 Binary Numbers
- hdu 1390 Binary Numbers
- hdu 1390 Binary Numbers
- Binary Numbers 1390 HDU
- HDU 1390 Binary Numbers
- hdu-oj 1390 Binary Numbers
- HDU 1390 Binary Numbers(数学题)
- HDU 1390 || ZOJ 1383 Binary Numbers
- 杭电Hdu 1390 Binary Numbers
- HDU 1390 Binary Numbers【进制转换】
- 杭电 HDU ACM 1390 Binary Numbers
- HDU Binary Numbers 1390(转换+统计)
- hdoj.1390 Binary Numbers 20140821
- HDOJ 1390 Binary Numbers(水题)
- Binary Numbers
- Binary Numbers
- Binary Numbers
- Leetcode 92. Reverse Linked List II (Medium) (cpp)
- Android 联系人数据库介绍以及对联系人的基本操作
- uva 572 Oil Deposits
- 欢迎使用CSDN-markdown编辑器
- python 开发简单爬虫 by CL(一)
- HDU 1390 Binary Numbers
- popwondows简单用法
- poj3762 The Bonus Salary! (mcmf 区间K覆盖问题)
- Android错误:cannot locate symbol "rand" referenced by "libgameshared.so
- 二分的两种重要模型
- 二叉树---检查是否为BST
- 努力不一定会成功,不努力一定不成功!
- 初学C语言:特殊乘法(单个数字字符去减‘0’得到的就是数字)
- Java 数据类型初始值