Binary Numbers

点我

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3820    Accepted Submission(s):
2321

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.

 
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 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.

 
Sample Input
1
13
 
Sample Output
0 2 3
 #include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
int T;
cin>>T;
while(T--)
{
int n,i=,j,k,flag=;
cin>>n;
while(n)
{
if(n%==)
{
cout<<i;
if(n>=)
cout<<' ';
}
i++;
n/=;
}
cout<<endl;
}
}
 
 

Binary Numbers(HDU1390)的更多相关文章

  1. 【gym102394B】Binary Numbers(DP)

    题意:From https://blog.csdn.net/m0_37809890/article/details/102886956 思路: 可以发现转移就是右上角的一个区间前缀和 std只要开1倍 ...

  2. 【CF662C】Binary Table(FWT)

    [CF662C]Binary Table(FWT) 题面 洛谷 CF 翻译: 有一个\(n*m\)的表格(\(n<=20,m<=10^5\)), 每个表格里面有一个\(0/1\), 每次可 ...

  3. Humble Numbers(hdu1058)

    Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  4. 【CF55D】Beautiful numbers(动态规划)

    [CF55D]Beautiful numbers(动态规划) 题面 洛谷 CF 题解 数位\(dp\) 如果当前数能够被它所有数位整除,意味着它能够被所有数位的\(lcm\)整除. 所以\(dp\)的 ...

  5. Round Numbers(组合数学)

    Round Numbers Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Tota ...

  6. PAT 甲级 1023 Have Fun with Numbers(20)(思路分析)

    1023 Have Fun with Numbers(20 分) Notice that the number 123456789 is a 9-digit number consisting exa ...

  7. Codeforces F. Vus the Cossack and Numbers(贪心)

    题目描述: D. Vus the Cossack and Numbers Vus the Cossack has nn real numbers aiai. It is known that the ...

  8. Codeforces663E Binary Table(FWT)

    题目 Source http://codeforces.com/contest/663/problem/E Description You are given a table consisting o ...

  9. Gym 100703G---Game of numbers(DP)

    题目链接 http://vjudge.net/contest/132391#problem/G Description standard input/outputStatements — It' s ...

随机推荐

  1. [C++程序设计]内置函数

    注意: 可以在声明函数和定义函数时同时写 inline,也可以只在其中一处声明inline,效果相同,都能按内置函数处理. 使用内置函数可以节省运行时间,但却增加了目标 程序的长度.因此一般只将规模很 ...

  2. iOS Plist NSUserDefaults 数据存储

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...

  3. JS+html实现简单的飞机大战

    摘要:通过原生的js+html实现简单的飞机大战小游戏效果,如图所示: 实现代码如下: 1.自己的飞机实现 飞机html: <!DOCTYPE html> <html lang=&q ...

  4. mysql-test库要命的地方

    为了见识test库对整个mysql实例安全的影响,我将建立一个appuser@'%' 用户,它只有一个权限那就是可以连接上mysql. 001. 以高权限用户登录mysql.创建一个appuser@' ...

  5. Linux下MySQL 5.6的修改字符集编码为UTF8(彻底解决中文乱码问题)

    一.登录MySQL查看用SHOW VARIABLES LIKE ‘character%’;下字符集,显示如下:+--------------------------+----------------- ...

  6. cxf2.7.10 与 spring3.0.5集成

    开发环境: NetBeans7.4 Tomcat 6.0.32 一 服务端: 1:新建JavaWeb工程 cxfspring-server,导入jar包如下图所示: 2:在web.xml文件中添加如下 ...

  7. 剑指offer-面试题16.反转链表

    题目:定义一个函数,输入一个链表的头结点,反转该链表并输出反转后的头结点 链表结点定义如下: struct ListNode { int m_nKey; ListNode* m_pNext; } 其实 ...

  8. linux下vi命令大全(转载)

    进入vi的命令 vi filename :打开或新建文件,并将光标置于第一行首 vi +n filename :打开文件,并将光标置于第n行首 vi + filename :打开文件,并将光标置于最后 ...

  9. 委托、Lambda表达式

    本文来自:http://wenku.baidu.com/link?url=o9Xacr4tYocCPhivayRQXfIc9kOZeWBwPn2FZfeF19P4-8YX5CMXs74WB-Y8t0S ...

  10. java File的getLastModified在不同操作系统以下存在差异

    java对文件读取改动时间(getLastModified())在不同的操作系统下存在差异  //1.在windows下,返回值是毫秒级别,不存在问题 //2.在Linux下,返回的值是毫秒值,可是会 ...