题解 | #牛牛的10类人#

牛牛的10类人

https://www.nowcoder.com/practice/232b7fc32fac4636819e31a7d7c960a3

#include <stdio.h>
void get(int* p)
{
	int l = 0, o = 0;
	int temp = *p;
	if (temp == 0)
		o++;
	while (temp)
	{
		if (temp % 2 == 1)
			l++;
		else
			o++;
		temp /= 2;//二进制数的位数移动
	}
	if (l % 2 == 0 && o % 2 != 0)
		printf("1 ");
	else if (l % 2 != 0 && o % 2 == 0)
		printf("0 ");
	else if (l % 2 == 0 && o % 2 == 0)
		printf("10 ");
	else
		printf("100 ");
}
int main()
{
	int n = 0;
	int arr[2000] = { 0 };
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &arr[i]);
		get(&arr[i]);
	}
	printf("\n");
	return 0;
}

全部评论

相关推荐

点赞 评论 收藏
分享
北枳的南橘:建议大家务必去和他沟通一下,像极了小学生对你侃侃而谈国际局势😂
找AI工作可以去哪些公司...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务