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 ...
随机推荐
- 区间dp实战练习
题解报告:poj 2955 Brackets(括号匹配) Description We give the following inductive definition of a “regular br ...
- P2629 好消息,坏消息
题目描述 uim在公司里面当秘书,现在有n条消息要告知老板.每条消息有一个好坏度,这会影响老板的心情.告知完一条消息后,老板的心情等于之前老板的心情加上这条消息的好坏度.最开始老板的心情是0,一旦老板 ...
- 关于Control.Dispatcher.BeginInvoke卡界面
Control.Dispatcher.BeginInvoke里的逻辑由UI线程执行,如果内部包含耗时操作就会造成界面卡住. Action.BeginInvoke里的逻辑,将在一个新开的线程中执行,而不 ...
- 分布式数据存储 之 Redis(一) —— 初识Redis
分布式数据存储 之 Redis(一) -- 初识Redis 为什么要学习并运用Redis?Redis有什么好处?我们步入Redis的海洋,初识Redis. 一.Redis是什么 Redis 是一个 ...
- echarts简单用法快速上手
1.html结构 简单说就是一个标签一个图表:2.初始化:var myEcharts = echarts.init(document.getElementById("xxx")): ...
- Python100天打卡-Day10-图形用户界面和游戏开发
基于tkinter模块的GUIPython默认的GUI开发模块是tkinter(在Python 3以前的版本中名为Tkinter)使用tkinter来开发GUI应用需要以下5个步骤: 导入tkinte ...
- centos7 系统安全加固方案
一.密码长度与有效期 默认配置: [root@i-1y3we23j ~]# cat /etc/login.defs |grep PASS_ |grep -v '#' PASS_MAX_DAYS PAS ...
- axure使用经验
泛化不常用======伸展也是拉动原件收缩也是拉动原件====== 动态模板相互影响(有的时候会出现这个问题,只需要设置两者的高度,不让两者有包含关系(一点点可以有):====== 实现高级菜单栏(同 ...
- linux下的基础操作
Xfce 终端: Linux 命令行终端,打开后会进入 zsh Shell 环境,可以使用 Linux 命令. NetSurf 网络浏览器:浏览器,可以用在需要前端界面的课程里,只需要打开环境里写的 ...
- activiti工作流学习链接
首页: http://www.activiti.org/书籍: activiti in action 入门demo: kft-activiti-demo http://www.oschina.n ...