文章

19

粉丝

0

获赞

125

访问

3.0k

头像
0和1的个数 题解:
P1008 华南师范大学/贵州大学机试
发布于2025年3月6日 18:56
阅读数 127

#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n, num0 = 0, num1 = 0;
	cin >> n;
	bitset<32> b(n); // 数字转32位二进制
	string s = b.to_string();
 	for(int i = 0; i < (int)s.length(); i++) {
	 	if(s[i] == '0') num0 ++;
	 	else num1 ++;
	}
	cout << "count0=" << num0 << " " << "count1=" << num1;
	 
 	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发