题解 | #求最大连续bit数#

求最大连续bit数

http://www.nowcoder.com/practice/4b1658fd8ffb4217bc3b7e85a38cfaf2

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int input;
    while(cin>>input)
    {
        int result = 0;
        int tmp = 0;
        for(int i=0; i<9; i++)
        {
            if(input&1 == 1)
            {
                tmp++;
            }
            else
            {
                if(tmp>result)
                {
                    result = tmp;
                    //cout<<result<<endl;
                }
                tmp = 0;
            }
            input = input>>1; // floor(input/2);
        }
        cout<<result<<endl;
    }
    return 0;
}
全部评论

相关推荐

叁六玖:你看,最后不是让你加油,就是鼓励你,还祝福你求职顺利。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务