1 条题解
-
0
C++ :
#include <iostream> using namespace std; // 函数: 计算两个整数的汉明距离 int hammingDistance(int x, int y) { int xorValue = x ^ y; // 异或运算 int distance = 0; while (xorValue) { distance += xorValue & 1; // 统计异或结果中1的个数 xorValue >>= 1; // 右移一位 } return distance; } int main() { int x, y; cin >> x >> y; // 读取输入 cout << hammingDistance(x, y) << endl; // 输出汉明距离 return 0; }
- 1
信息
- ID
- 1487
- 时间
- 2000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者