两个整数之间的汉明距离是指这两个数与二进制比特的不同位置对应的数。
【输入形式】
给定两个整数x和y(0=x,y2^31 ),用空格分隔
【输出形式】
输出他们之间的汉明距离
【样品输出】
1 4
【样品说明】
00000000 00000000 00000000 00000001
00000000 00000000 00000000 00000100
想法:首先对输入的两个数进行异或操作。 相同时为0,不同时为1; 然后判断含有多少个1就可以了。 # include iostream # include stdio.hint func (intx ); using namespace std; int main () { int HM,a,b,distance; cin ab; HM=a ^ b; distance=func(hm; printf('%d”,distance; 返回0; (intfunc ) intx ) { int countx=0; while(x ) { countx; x=x(x-1 ); } return countx; }