求最大连续bit数

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    while (cin >> n)
    {
        int count = 0, maxsize = 0;
        while (n)
        {
            if (n & 1)
            {
                count++;
                maxsize = max(maxsize, count);
            }
            else
            {
                count = 0;
            }
            n = n >> 1;
        }
        cout << maxsize << endl;
    }
    system("pause");
    return 0;
}

发布了81 篇原创文章 · 获赞 1 · 访问量 2755

猜你喜欢

转载自blog.csdn.net/weixin_44781382/article/details/105018584