题解 | #求最大连续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;
}

全部评论

相关推荐

点赞 评论 收藏
分享
08-14 13:51
门头沟学院 Java
没有任何游戏经验....
投递米哈游等公司8个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务