题解 | #两个整数二进制位不同个数#

两个整数二进制位不同个数

https://www.nowcoder.com/practice/16e48900851646c0b2c6cdef9d7ea051

#include <stdio.h>

int main() {
    int a, b;
    int count=0;
    while (scanf("%d %d", &a, &b) != EOF) { // 注意 while 处理多个 case
        // 64 位输出请用 printf("%lld") to
        int tmp=a^b;
        while(tmp)
        {
            tmp=tmp&(tmp-1);
            count++;
        } 
        printf("%d\n", count);
    }
    return 0;
}

全部评论

相关推荐

wu970:标准北漂配置,怎么看着装修风格有点像自如的😭
点赞 评论 收藏
分享
政委qqq:这道题在算法竞赛里唯一考的就是高精度,但是只能难住C++这类语言,Python直接a+b秒天秒地
点赞 评论 收藏
分享
评论
7
收藏
分享

创作者周榜

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