题解 | #两个整数二进制位不同个数#
两个整数二进制位不同个数
https://www.nowcoder.com/practice/16e48900851646c0b2c6cdef9d7ea051
#include <stdio.h>
int main() {
int a, b;
while (scanf("%d %d", &a, &b) != EOF) { // 注意 while 处理多个 case
// 64 位输出请用 printf("%lld") to
int c = a ^ b;
int d = 0;
int count = 0;
while(c)
{
d = c%2;
if(d == 1)
{
count++;
}
c /= 2;
}
printf("%d\n", count);
}
return 0;
}
查看21道真题和解析