1 条题解
-
0
C++ :
#include <iostream> using namespace std; // 函数: 计算整数二进制表示中1的个数 int countOnes(int n) { int count = 0; while (n) { count += n & 1; // 统计最低位是否为1 n >>= 1; // 右移一位 } return count; } int main() { int n; cin >> n; // 读取输入 cout << countOnes(n) << endl; // 输出1的个数 return 0; }
- 1
信息
- ID
- 1485
- 时间
- 2000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者