第39259题 组合题
阅读程序(第一题):统计二进制位数与 1 的个数

以下问题均假定输入的 n 为不超过 2^31 − 1 的非负整数。

#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int x = 1, y = 1;
  while (n > 0) {
    if (n % 2 == 0) {
      ++x;
    } else {
      ++x;
      ++y;
    }
    n = n / 2;
  }
  cout << x << ' ' << y << endl;
  return 0;
}
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
程序运行统计
暂无判题统计
知识点:
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析