当前位置:网站首页>[51nod.3210] binary Statistics (bit operation)

[51nod.3210] binary Statistics (bit operation)

2022-06-13 02:06:00 Python's path to becoming a God

Binary statistics

Subject portal
 Insert picture description here

sample input

5
1
2
4
8
16

sample output

1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Their thinking

Binary system

AC Code

#include<cstdio>
using namespace std;
int n,ans[32];
int main()
{ 
    
	scanf("%d",&n);
	while(n--)
	{ 
    
		int x,sum=0;
		scanf("%d",&x);
		x&=-x;
		x>>=1;
		while(x)
		{ 
    
			x>>=1;
			sum++;
		}
		ans[sum]++;
	} 
	for(int i=0;i<=31;i++)
		printf("%d ",ans[i]);
	return 0;
}

thank you

原网站

版权声明
本文为[Python's path to becoming a God]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280547569093.html