#2616. 2026 CSP-J1 真题 · 阅读程序1

2026 CSP-J1 真题 · 阅读程序1

2026 CSP-J1 真题(120 分钟,总分 100 分)

阅读程序1(共 6 题,共 13 分)

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;
}

(本题 1 分)当输入为 3 时,程序输出 3 3。

{{ select(1) }}

  • 正确
  • 错误

2.

#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;
}

将第 11 行的 ++x; 删除后,程序输出的两个数一定相等。

{{ select(2) }}

  • 正确
  • 错误

3.

#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;
}

假设输入为非负整数,则程序输出的第一个数一定不小于第二个数。

{{ select(3) }}

  • 正确
  • 错误

4.

#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;
}

将第 7 行的 while (n > 0) 改为 while (n >= 0) 后,程序可能出现的问题是( )。

{{ select(4) }}

  • 陷入死循环
  • 输出结果比原来大
  • 输出结果比原来小
  • 输出结果不受影响

5.

#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;
}

当输入为 6 时,输出为( )。

{{ select(5) }}

  • 3 3
  • 4 2
  • 4 3
  • 5 2

6.

#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;
}

若输入 n 依次取遍 0, 1, 2, …, 2³¹ − 1 中的所有整数,则程序输出的第二个数恰好为 2 的次数为( )。

{{ select(6) }}

  • 16
  • 30
  • 31
  • 32