题解 | #求最大连续bit数#
求最大连续bit数
https://www.nowcoder.com/practice/4b1658fd8ffb4217bc3b7e85a38cfaf2
#include <stdio.h>
int main() {
int n, count, maxcount = 0;
while (scanf("%d", &n) != EOF) {
// printf("the input number is %d\n", n);
while(n > 0) {
count = 0;
while(n & 1){
count++;
// printf("encounter one, now count is %d\n", count);
n >>= 1;
}
if(count > maxcount) maxcount = count;
// printf("maxcount now is %d\n", maxcount);
n >>= 1;
}
printf("%d\n", maxcount);
}
return 0;
}
查看7道真题和解析