题解 | #求最大连续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);


    
}

全部评论

相关推荐

扉川川:查看图片
投递用友等公司10个岗位
点赞 评论 收藏
分享
07-07 17:06
已编辑
深圳技术大学 golang
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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