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

 1 <= n <= 10^6

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的更多相关文章

  1. HDU-1390 Binary Numbers

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

  2. Binary Numbers(HDU1390)

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

  3. zoj 1383 Binary Numbers

    Binary Numbers Time Limit: 2 Seconds      Memory Limit: 65536 KB Given a positive integer n, print o ...

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

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

随机推荐

  1. oracle spfile和pfile文件

    pfile(Parameter File)从oracle8i开始使用,在oracle9i中也可以用.它以文本文件的形式存在,可以用vi等编辑器对 其中数据库参数进行修改.文件格式为initSID.or ...

  2. 洛谷 P1156 垃圾陷阱

    2016-05-31 09:54:03 题目链接 :洛谷 P1156 垃圾陷阱 题目大意: 奶牛掉坑里了,给定坑的深度和方块的个数,每个方块都可以垫脚或者吃掉维持生命(初始为10) 若可以出来,求奶牛 ...

  3. 安装ADT

    ubuntu下安装android开发环境. 打开eclipse,help---install new software,安装adt,一直提示无法连接到dl-ssl.google.com 由https改 ...

  4. Enterprise Suse运维

    1,Suse CDH4安装 wget archive.cloudera.com/cdh4/one-click-install/redhat/6/x86_64/cloudera-cdh-4-0.x86_ ...

  5. hdoj 1229 还是A+B

    还是A+B Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  6. windows程序员进阶系列:《软件调试》之堆 (一)

    windows程序员进阶系列:<软件调试>之堆 (一) 堆是软件在运行时动态申请内存空间的主要途径.从堆上申请来的空间需要程序员自己申请和释放,且申请和释放操作必须绝对匹配.忘记释放或者多 ...

  7. javascript之函数篇

    1.我们都知道定义函数有两种方式:函数声明和函数表达式(其实还有Function构造函数方式,不推荐使用) 如: 声明方式:function sum(num1,num2){returm num1+nu ...

  8. Ognl表达式语言

    l  OGNL表达式 OGNL是Object Graphic Navigation Language(对象图导航语言)的缩写,它是一个开源项目. Struts2框架使用OGNL作为默认的表达式语言. ...

  9. Asp.Net事务和异常处理:

    Asp.Net事务和异常处理: 一.什么是事务处理? 事务处理是一组组和成逻辑工作单元的数据库操作,虽然系统中可能会出错,但事务将控制和维护每个数据库的一致性和完整性. 如果在事务过程中没有遇到错误, ...

  10. Android动画Animation之Tween用代码实现动画

    透明度动画.旋转动画.尺寸伸缩动画.移动动画 package com.javen.tween; import android.annotation.SuppressLint; import andro ...