Binary Numbers


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 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>
#include <vector>
using namespace std;
int main(){
int d, n, flag;
vector<int> v;
cin >> d;
while(cin >> n){
v.clear();
while(n){
int t = n % ;
v.push_back(t);
n >>= ;
}
flag = ;
for(int i = ; i < v.size(); i++){
if(v[i] == ){
if(flag == ){
cout << i;
flag = ;
} else {
cout << " " << i;
}
}
}
cout << endl;
}
//system("pause");
return ;
}

zoj 1383 Binary Numbers的更多相关文章

  1. ZOJ Problem Set - 1383 Binary Numbers

    水题,输出的时候注意下 #include <stdio.h> #include <math.h> int main() { int d; scanf("%d" ...

  2. HDU-1390 Binary Numbers

    http://acm.hdu.edu.cn/showproblem.php?pid=1390 Binary Numbers Time Limit: 2000/1000 MS (Java/Others) ...

  3. Binary Numbers(HDU1390)

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

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

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

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

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

  7. [Swift]LeetCode1022. 从根到叶的二进制数之和 | Sum of Root To Leaf Binary Numbers

    Given a binary tree, each node has value 0 or 1.  Each root-to-leaf path represents a binary number ...

  8. ZOJ - 2243 - Binary Search Heap Construction

    先上题目: Binary Search Heap Construction Time Limit: 5 Seconds      Memory Limit: 32768 KB Read the sta ...

  9. Binary Numbers AND Sum CodeForces - 1066E (前缀和)

    You are given two huge binary integer numbers aa and bb of lengths nn and mmrespectively. You will r ...

随机推荐

  1. 题解报告:hdu 4135 Co-prime(容斥定理入门)

    Problem Description Given a number N, you are asked to count the number of integers between A and B ...

  2. MVC模式到传统风格的Spring MVC

    现在我们要做个简单的基于servlet的MVC的模型,我们要有一个Product要从表单处获取. MVC中的M是模型,V是视图,C是控制器.视图负责应用的展示,模型封装了数据和业务逻辑,控制器负责接收 ...

  3. (028)[技术资料]et99加密狗打开函数的一个小bug

    et99加密狗的打开函数,其官方vb调用申明如下:Declare Function et_OpenToken Lib "FT_ET99_API.dll" (ByRef et99ha ...

  4. 搭建一个高可用的redis环境

    一.环境准备 我的环境: Fedora 25 server  64位版 6台: 192.168.10.204 192.168.10.205 192.168.10.206 192.168.10.203 ...

  5. [转]VC++中对文件的写入和读取

    本文转自:http://blog.csdn.net/fanghb_1984/article/details/7425705 本文介绍两种方法对文件进行读取和写入操作:1.采用fstream类:2.采用 ...

  6. configure: error: MySQL library not found

    在CentOS系统中,安装zabbix进行configure时会遇到以下问题 ./configure --enable-server --enable-agent --with-mysql --wit ...

  7. qt qtableview 样式设置

    转载请注明出处:http://www.cnblogs.com/dachen408/p/7531159.html 1.设置tableview的列宽时,必须先setModel再setColumnWidge ...

  8. JavaScript 声明全局变量与局部变量

    一.JavaScript 声明全局变量的三种方式: 声明方式一: 使用var(关键字)+变量名(标识符)的方式在function外部声明,即为全局变量,否则在function声明的是局部变量.该方式即 ...

  9. Open Cascade创建自己的MFC文档程序

    项目初始设置在Visual studio中创建一个单文档MFC项目(本例以MFCTest为名称): 在项目属性的VC++页面设置包含目录.库目录,在链接器的输入中添加OCC库目录下的所有.lib文件名 ...

  10. MySQL-06 数据备份和恢复

    学习目标 数据备份 数据恢复 数据库迁移 导入和导出 数据备份 系统意外崩溃或者服务器硬件损坏都有可能导致数据库丢失,因此生产环境中数据备份非常重要. MySQLdump命令备份 该命令可以将数据库备 ...