http://acm.hdu.edu.cn/showproblem.php?pid=1390

Binary Numbers

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

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
 
Source
 
Recommend
Ignatius.L

#include<stdio.h>
int main()
{
int d,n,r,a[],j,i,f;
scanf("%d",&d);
while(d--)
{
j=;
scanf("%d",&n);
while(n!=)
{
r=n%;
a[j++]=r;
n=n/;
}
for(i=;i<j;i++)
if(a[i]==)
{
f=i;
printf("%d",i);
break;
}
for(i=f+;i<j;i++)
if(a[i]==)
printf(" %d",i);
printf("\n");
}
return ;
}

HDU-1390 Binary Numbers的更多相关文章

  1. HDOJ 1390 Binary Numbers(进制问题)

    Problem Description Given a positive integer n, find the positions of all 1's in its binary represen ...

  2. Binary Numbers(HDU1390)

    Binary Numbers 点我 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  3. 【数位DP】 HDU 4722 Good Numbers

    原题直通车: HDU  4722  Good Numbers 题意: 求区间[a,b]中各位数和mod 10==0的个数. 代码: #include<iostream> #include& ...

  4. HDU 3117 Fibonacci Numbers(围绕四个租赁斐波那契,通过计++乘坐高速动力矩阵)

    HDU 3117 Fibonacci Numbers(斐波那契前后四位,打表+取对+矩阵高速幂) ACM 题目地址:HDU 3117 Fibonacci Numbers 题意:  求第n个斐波那契数的 ...

  5. HDOJ(HDU).1058 Humble Numbers (DP)

    HDOJ(HDU).1058 Humble Numbers (DP) 点我挑战题目 题意分析 水 代码总览 /* Title:HDOJ.1058 Author:pengwill Date:2017-2 ...

  6. Codeforces Round #515 (Div. 3) E. Binary Numbers AND Sum

    E. Binary Numbers AND Sum 题目链接:https://codeforces.com/contest/1066/problem/E 题意: 给出两个用二进制表示的数,然后将第二个 ...

  7. zoj 1383 Binary Numbers

    Binary Numbers Time Limit: 2 Seconds      Memory Limit: 65536 KB Given a positive integer n, print o ...

  8. 【Leetcode_easy】1022. Sum of Root To Leaf Binary Numbers

    problem 1022. Sum of Root To Leaf Binary Numbers 参考 1. Leetcode_easy_1022. Sum of Root To Leaf Binar ...

  9. LeetCode 1022. 从根到叶的二进制数之和(Sum of Root To Leaf Binary Numbers)

    1022. 从根到叶的二进制数之和 1022. Sum of Root To Leaf Binary Numbers 题目描述 Given a binary tree, each node has v ...

随机推荐

  1. react native ios 开发,基础配置笔记。

    一.获取硬件信息,使用react-native-device-info插件,配置说明: 1.首先需要安装组件:npm install react-native-device-info --save 2 ...

  2. (hdu)5652 India and China Origins 二分+dfs

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5652 Problem Description A long time ago there ...

  3. cocos2dx如何添加popScene的场景动画

    说明 我们很容易在pushScene中添加动画 Director::getInstance()->pushScene(TransitionSlideInB::create(SCENE_TIME, ...

  4. ASP.NET中的特殊路径标识"~"

    / 表示网站根目录(从域名开始), ../ 表示上级目录, ./表示当前目录- 是ASP.NET定义的特殊符号,是ASP.NET内部进行定义推荐的用法,-代表从应用根目录开始定义应用根目录与网站根目录 ...

  5. 思维导图软件VYM

    http://www.insilmaril.de/vym/ 点击打开链接http://www.oschina.net/p/vym 有人说VYM就跟目录是一回事,确实是这样, 只不过与excel之类的比 ...

  6. 【原创】Android多个xml文件的使用

    Android中经常会使用多个xml文件,但在Mainactivity中使用的setContentView(R.layout.main)只加载main.xml文件,其他xml文件不加载进当前视图,当我 ...

  7. c#语音

    1.新建WinForm程序,项目名称命名为Speech. 2.在COM组件中添加SpeechLib的引用. using SpeechLib;//添加语音引用 添加一个文本框并将其重命名为txtCont ...

  8. [C#]『Barrier』任务并行库使用小计

    Barrier  是一个对象,它可以在并行操作中的所有任务都达到相应的关卡之前,阻止各个任务继续执行. 如果并行操作是分阶段执行的,并且每一阶段要求各任务之间进行同步,则可以使用该对象. --MSDN ...

  9. HTML块

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  10. 小笔记(二):php数组

    一.对于一二维数组重新组合为另一个二维数组,根据键值名称对一个二维数组进行重新组合例: /*$paramArray=array( * 'a'=>array('0'=>'1','1'=> ...