华为oj 015

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_25244495/article/details/82193620

【华为OJ】【015-求int型数据在内存中存储时1的个数】

题目链接:

https://blog.csdn.net/DERRANTCM/article/details/51319753

C++实现:

void main()
{
	int n1,n2,n3,n4;
	string str1,strOut;

	cin >> n1;
	n2 = 0;
	while(n1 != 0)
	{
		n2 += n1 & 0x01;
		n1 >>= 1;
	}
	cout << n2 << endl;

	system("pause");
}

猜你喜欢

转载自blog.csdn.net/qq_25244495/article/details/82193620
今日推荐