文章

36

粉丝

504

获赞

54

访问

353.7k

头像
题解:0和1的个数
P1008 华南师范大学/贵州大学机试
发布于2020年2月29日 23:59
阅读数 10.5k

分享个函数,__builtin_popcount(),返回int类型的数二进制下1的个数

#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int ans = __builtin_popcount(n);
	printf("count0=%d count1=%d", 32 - ans, ans);
	return 0;
}

 

登录查看完整内容


登录后发布评论

1 条评论
daiwei VIP
2020年3月4日 15:45

厉害了

 

赞(0)