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