最大连续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;
}

 

posted @ 2020-07-30 17:23  repinkply  阅读(230)  评论(0)    收藏  举报