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

求最大连续bit数

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

#include <iostream>
using namespace std;

int main() {
    int input;
    while (cin >> input) {
        int x = 0;
        int count = 0;
        while (input / 2 != 0) {
            if (input % 2 == 1) {
                count++;
            }
            if (input % 2 == 0) {
                count = 0;
            }
            if (x < count) {
                x = count;
            }
            input /= 2;
        }
        count++;
        if (x < count) {
            x = count;
        }
        cout << x << endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

06-25 16:25
梧州学院 Java
愿汐_:项目介绍那么长,然而你做了啥就一句话?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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