最大连续bit数 (HJ86)
C++代码如下:
#include <iostream> #include <algorithm> using namespace std; int main() { int n = 0; while (cin >> n) { int count = 0; int maxCount = 0; while (n != 0) { if (n & 1) { count++; maxCount = max(maxCount,count); } else { count = 0; } n >>= 1; } cout << maxCount << endl; } return 0; }

浙公网安备 33010602011771号