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

求最大连续bit数

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

#include <stdio.h>
#include <string.h>
int main() {
    int a,count,max;
    int i=0;
    char str[1000];
    memset(&str, 0 , sizeof(str));
    scanf("%d",&a);

    while (a!=0){
        if(a%2==1)
            str[i]='1';
        else 
            str[i]='0';
        a=a/2;
        i++;
    }//二进制字符串

    for (int j=0; j<=i; j++) {
        count=0;
        while(str[j]=='1') {
            count++;
            if(count>max)
                max=count;
            j++;
        }
        

    }
    printf("%d",max);


    
}

全部评论

相关推荐

不多说了,看图吧
MomonKa:实际上是,机房机器有些高度,问问你身高,有没有女朋友是看你能不能猛猛加班
你最讨厌面试问你什么?
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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