【十二题解】 | #求最大连续bit数#
求最大连续bit数
http://www.nowcoder.com/practice/4b1658fd8ffb4217bc3b7e85a38cfaf2
#include<stdio.h>
int f_max(int a, int b){ return a>b?a:b; }
int main(){
int number;
while(scanf("%d", &number) != EOF){
int lenth = 0;
int ans = 0;
for(int i=0; i<21; i++){
if(number & 1 == 1){
lenth++;
}
else{
ans = f_max(ans, lenth);
lenth = 0;
}
number >>= 1;
}
printf("%d\n", ans);
}
}