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

求最大连续bit数

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

#include <stdio.h>

int main() {
    int n, count, maxcount = 0;
    while (scanf("%d", &n) != EOF) {
        // printf("the input number is %d\n", n);
        while(n > 0) {
            count = 0;
            while(n & 1){
                count++;
                // printf("encounter one, now count is %d\n", count);
                n >>= 1;
            }
            if(count > maxcount) maxcount = count;
            // printf("maxcount now is %d\n", maxcount);
            n >>= 1;
        }
        printf("%d\n", maxcount);
    }
    return 0;
}

全部评论

相关推荐

哞客37422655...:你猜为什么福利这么好还得一直追着你问
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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