两个整数 m 和 n 的二进制表达中有多少个位(bit)不同?
数据范围:
#include <stdio.h> #include <stdlib.h> int main() { unsigned int x,y; while(scanf("%d %d",&x,&y)!=EOF) { unsigned int temp=x^y; int count=0; while(temp) { if(temp%2) { count++; } temp/=2; } printf("%d\n",count); } return 0; }
#include <stdio.h> #include <stdlib.h> int main(void) { int m, n; fscanf(stdin, "%d %d", &m, &n); return fprintf(stdout, "%d", __builtin_popcount(m ^ n)), 0; }