hackerrank Day 10: Binary Numbers
Task
Given a base-10 integer, n, convert it to binary (base-2). Then find and print the base-10 integer denoting the maximum number of consecutive 1's in n's binary representation.
Input Format
A single integer, n.
Constraints
Output Format
Print a single base-10 integer denoting the maximum number of consecutive 1's in the binary representation of n.
Sample Input 1
5
Sample Output 1
1
Sample Input 2
13
Sample Output 2
2
Explanation
Sample Case 1:
The binary representation of 5 is 101, so the maximum number of consecutive 1's is 1.
Sample Case 2:
The binary representation of 13 is 1101 , so the maximum number of consecutive 1's is 2.
#include <iostream>
using namespace std; int main(){
int n;
cin >> n;
int temp = n;
int num = , max = ;
while(temp){
num = ;
while(temp & ){
num++;
temp >>= ;
}
if(num > max)
max = num;
temp >>= ;
}
cout << max << endl;
return ;
}
hackerrank Day 10: Binary Numbers的更多相关文章
- 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 ...
- zoj 1383 Binary Numbers
Binary Numbers Time Limit: 2 Seconds Memory Limit: 65536 KB Given a positive integer n, print o ...
- 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 ...
- 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 ...
- 【leetcode】1022. 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 n ...
随机推荐
- 安装mysql-5.7.9-winx64
1.mysql-5.7.9-winx64.zip下载 官方网站下载地址:http://dev.mysql.com/downloads/mysql/5.7.html 2.解压到D:\MySqlDataB ...
- Crash的旅行计划
除草了.. Crash的旅行计划 [问题描述] 过不了多久,Crash就要迎来他朝思暮想的暑假.在这个暑假里,他计划着到火星上旅游.在火星上有N个旅游景点,Crash用1至N这N个正整数对这些景点标号 ...
- Tcp/Ip协议族简单解读及网络数据包/报/帧数据格式及封装及解包;
http://www.creseek.cn/products-install/install_on_bsd_linux/ 中文检索 离线cloudera ecosystem components: h ...
- HDU 3488--Tour(KM or 费用流)
因为每个点只能经过一次 所以考虑拆点 这题有坑,有重边.. KM算法 把一个点拆成入点和出点 入点在X部,出点在Y步. 如果u,v之间有路径,就在X部的u点连接Y部的v点 求完美匹配. 当完美匹配的时 ...
- python 类和实例
面向对象最重要的概念就是类(Class)和实例(Instance),必须牢记类是抽象的模板,比如Student类,而实例是根据类创建出来的一个个具体的“对象”,每个对象都拥有相同的方法,但各自的数据可 ...
- [OC Foundation框架 - 14] NSNull
在NSDictionary中,nil代表结束,允许存入 使用NSNull代替 int main(int argc, const char * argv[]) { @autoreleasepool ...
- Linux--用SecureCRT来上传和下载文件
SecureCRT下的文件传输协议有以下几种:ASCII.Xmodem.Ymodem.Zmodem ASCII:这是最快的传输协议,但只能传送文本文件. Xmodem:这种古老的传输协议速度较慢,但由 ...
- The Sorrows of Young Werther
The Sorrows of Young Werther J.W. von Goethe Thomas Carlyle and R.D. Boylan Edited by Nathen Haskell ...
- 某项目 需要在UITabbar 上显示小红点,在此搜罗了三个方法。
1.使用系统自带的,并且可以在小红点上显示数字. [itemOne setBadgeValue:@""]; //显示不带数字的小红点 [itemOne setBadgeValue: ...
- 动网论坛password暴力破解程序代码
<% response.buffer=false '为防止程序陷入死循环,初始化一些最大重试值 Dim MaxPassLen,MaxPassAsc MaxPassLen=20 'pass ...