方法1:
#include<stdio.h>
int count(int m, int n)
{
int count = 0;
int ret = m ^ n;
while (ret)
{
ret = ret & (ret - 1);
count++;
}
return count;
}
int main()
{
int m, n;
scanf("%d %d", &m, &n);
int ret = count(m, n);
printf("%d", ret);
return 0;
}
方法2:
#include<stdio.h>
int count(int m, int n)
{
int i,count=0;
for (i = 9; i < 32; i++)
{
if (((m >> i) & 1 )!= ((n >> i) & 1))
{
count++;
}
}
return count;
}
int main()
{
int m,n;
scanf("%d %d", &m, &n);
int ret = count(m, n);
printf("%d", ret);
return 0;
}