文章

49

粉丝

49

获赞

8

访问

10.3k

头像
C++
P1008 华南师范大学/贵州大学机试
发布于2024年3月17日 10:39
阅读数 174

#include<iostream>
#include<string>
using namespace std;

int main()
{
	int n;
	cin >> n;
	string s;
	while (n)
	{
		s += n % 2 + '0';
		n /= 2;
	}
	int count0 = 0, count1 = 0;
	for (auto i = s.begin(); i != s.end(); i++)
	{
		if (*i == '1')
		{
			count1++;
		}
	}
	count0 = 32 - count1;
	cout << "count0=" << count0 << " " << "count1=" << count1 << endl;
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发