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

求最大连续bit数

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

位移操作,

#include <stdio.h>

int main() {
    int a;
    int count = 0;
    int max_bit = 0;
    int x = 0, y = 0;
    scanf("%d", &a);
    for (int i = 0; i < 64; i++) {//64位
        for (int j = 0; j < 64; j++) {
            count = 0;
            x = i;
            y = j;
            while ((a >> x) & (0x80 >> y) != 0) {
                count++;
                x++;
                y++;
            }
            if (max_bit < count) {
                max_bit = count;
            }
        }
    }
    printf("%d\n", max_bit);
    return 0;
}

全部评论

相关推荐

03-10 21:11
武汉大学 运营
学不懂的那种:先天考公圣体
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务