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 ...
随机推荐
- linux高负载下mysql数据库彻底优化
同时在线访问量继续增大 对于1G内存的服务器明显感觉到吃力严重时甚至每天都会死机 或者时不时的服务器卡一下 这个问题曾经困扰了我半个多月MySQL使用是很具伸缩性的算法,因此你通常能用很少的内存运行或 ...
- C#基础学习1
开发入门,最基础的学习!
- Sqlserver调用WebApi
原文地址 http://www.cnblogs.com/lflyq/p/6065160.html sp_configure 'show advanced options', 1;GORECONFI ...
- c#内存管理,垃圾回收和资源释放
<1>关于虚拟内存的概念 Windows使用一个虚拟寻址系统,该系统把程序可用的内存地址映射到硬件内存中的实际地址上去,这些任务完全由windows后台管理,其实际结果是32位处理机上的每 ...
- 《Redis开发与运维》快速笔记(一)
1.前言&基本介绍 在原始的系统架构中,我们都由程序直接连接DB,随着业务的进一步开展,DB的压力越来越大,为了缓解DB的这一压力,我们引入了缓存,在程序连接DB中加入缓存层, 从而减轻数据库 ...
- iOS 开发App捕获异常, 反馈给服务器, 提高用户体验
在我们开发的app中, 不可避免的, 有时候用户使用软件会崩溃. 我们就需要捕获异常, 可以在入口类中加入相应的代码, 可以在每次用户打开程序的时候, 检查一下沙盒中是否有崩溃日志, 如果有, 可以 ...
- Kotlin学习的一些笔记
Introduction 写在前面 关于本书 这本书适合你吗? 关于作者 介绍 什么是Kotlin? 我们通过Kotlin得到什么 准备工作 Android Studio 安装Kotlin插件 创建一 ...
- Synplify FPGA 逻辑综合
作为 Synopsys FPGA 设计解决方案的一部分,Synplify FPGA 综合软件是实现高性能.高性价比的 FPGA 设计的行业标准. 其独特的行为提取综合技术 (Behavior Extr ...
- windows 下防火墙安全加固,配置规则
netsh advfirewall firewall: 显示关于防火墙操作的常见命令的帮助信息 netsh advfirewall firewall show rule name=all dir=in ...
- react基础语法(三)组件的创建和复合组件
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...