题解 | #求最大连续bit数#
求最大连续bit数
https://www.nowcoder.com/practice/4b1658fd8ffb4217bc3b7e85a38cfaf2
#include <iostream> using namespace std; int main() { int num; int tem = 0; int res = 0; int x = 1; while (cin >> num) { // 注意 while 处理多个 case x = 1; tem = 0; res = 1; while (num >= x) { if ((num & x) == x) { tem++; }else{ if(tem>res){ res = tem; } tem = 0; x<<=1; continue; } if(tem>res){ res = tem; } x<<=1; } cout<<res<<endl; } }