zoj 1383 Binary Numbers
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的更多相关文章
- ZOJ Problem Set - 1383 Binary Numbers
水题,输出的时候注意下 #include <stdio.h> #include <math.h> int main() { int d; scanf("%d" ...
- HDU-1390 Binary Numbers
http://acm.hdu.edu.cn/showproblem.php?pid=1390 Binary Numbers Time Limit: 2000/1000 MS (Java/Others) ...
- Binary Numbers(HDU1390)
Binary Numbers 点我 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- Codeforces Round #515 (Div. 3) E. Binary Numbers AND Sum
E. Binary Numbers AND Sum 题目链接:https://codeforces.com/contest/1066/problem/E 题意: 给出两个用二进制表示的数,然后将第二个 ...
- 【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 ...
- 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 ...
- [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 ...
- ZOJ - 2243 - Binary Search Heap Construction
先上题目: Binary Search Heap Construction Time Limit: 5 Seconds Memory Limit: 32768 KB Read the sta ...
- 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 ...
随机推荐
- Eclipse 运行内存不足情况
在debug或者run 时 在VM arguments 处添加 -Xms512m -Xmx512m
- Unity3D中GameObject 详细介绍
通过Hierarchy面板下的Create菜单可以手动地创建一个GameObject,它可以是一个相机,一个灯光,或者一个简单的模型,当我们要在程序里面动态地创建一个相机的时候,可以new一个Game ...
- Codeforces Round #243 (Div. 1)
---恢复内容开始--- A 枚举l,r #include <iostream> #include<cstdio> #include<cstring> #inclu ...
- PHP设计模式 观察者模式(Observer)
定义 当一个对象状态发生改变时,依赖它的对象全部会收到通知,并自动更新. 模式要点 Event:事件 Trigger() 触发新的事件 abstract EventGenerator 事件产生者 Fu ...
- re正则表达式公式讲解6
标识符 re.I (re.IGNORECASE) 忽略大小写 import re s = "Max@123uyt146" print(re.search("m" ...
- XML基本概念及增删改查操作
一.概念及特征: 1. XML 指可扩展标记语言(Extensible Markup Language),用户可以自己定义标签.XML 被设计用来传输和存储数据,而 HTML 用于格式化并显示数据,并 ...
- MongoDB最简单的入门教程之一 环境搭建
MongoDB是近年来非常流行的一个介于关系数据库和非关系数据库之间的解决方案,特别广泛地应用于国内很多互联网公司,是非关系数据库当中功能最丰富,最像关系数据库的. MongoDB支持的数据结构非常松 ...
- liunx 常用的命令
常用命令 ======================输入模式=================== Ctrl+d 向前缩进 Ctrl+t 向后缩进 =====================光标模式 ...
- Eclipse 下载 开源项目 maven依赖丢失和 Deployment Assembly 丢失
周末下载了最新的jeecg的源码来瞅瞅,但是下载后发现,pom文件中定义的依赖都丢失了. 如下图 上网搜索了一下啊,发现需要先给这个项目这个项目 disable maven nature 然后再添加上 ...
- 基于纯注解的spring开发的介绍
几个核心注解的介绍1.@Configuration它的作用是:将一个java类修饰为==配置文件==,在这个java类进行组件注册1package com.kkb.config; import org ...