题解 | #求最大连续bit数#
求最大连续bit数
https://www.nowcoder.com/practice/4b1658fd8ffb4217bc3b7e85a38cfaf2
// HJ86 求最大连续bit数.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 #include<iostream> #include<bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { int count = 0,res=0; while (n) { while ((n & 1) == 1) { n >>= 1; count++; } res = max(count, res); count = 0; n >>= 1; } cout << res << endl; } return 0; }