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