#10981. 2025年信息素养大赛初赛-客观题(初中组)

0

2025年信息素养大赛初赛-客观题(初中组)

一、单项选择题(每题5分,共15题,75分)

第1题

C++程序流程控制的基本结构不包括以下哪项?

{{ select(1) }}

  • 分支结构
  • 数据结构
  • 循环结构
  • 顺序结构

第2题

以下哪段代码能将数组 int a[4] = {2, 4, 6, 8}; 的所有元素变为原来的二倍?

{{ select(2) }}

  • for (int i=0; i<4; i++) a[i] += 2;
  • for (int i=0; i<4; i++) a[i] *= 2;
  • for (int i=1; i<=4; i++) a[i] = a[i] * a[i];
  • for (int i=1; i<=4; i++) a[i] *= 2;

第3题

以下哪项是分支结构的正确写法?

{{ select(3) }}

  • while (n > 0) cout << "Positive";
  • if (x>0) { cout << "Positive"; else cout << "Not"; }
  • if (x > 0) cout << "Positive";
  • for (int i=0; i<n; i++) cout << "Positive";

第4题

执行以下代码,输出的结果是?

int a = 14 / 3 * 3;
cout << a;

{{ select(4) }}

  • 14
  • 3
  • 0
  • 12

第5题

找出以下代码中哪一行是C++中合法的注释?

{{ select(5) }}

  • (注释此条语句)
  • //注释此条语句
  • #注释此条语句

第6题

以下说法正确的是?

{{ select(6) }}

  • 执行代码 cout << 13.8 % 2; 会输出1.8
  • 如果代码中不含有 #include 将无法通过编译
  • 将一个浮点数赋值给一个 char 类型的变量会出现运行时错误
  • C++可以定义无返回值且无参数函数

第7题

执行下列C++代码后,计算 s[0].d + s[1].i 的结果是多少?

struct S { double d; int i; };
S s[2] = {{1.5, 1}, {2.5, 2}};

{{ select(7) }}

  • 3.5
  • 4.5
  • 3
  • 4

第8题

补全以下代码,将数组 a 按升序排列。下列选项中哪一项正确?

int a[7] = {7, 1, 4, 2, 2, 3, 6};
int N = 7;
for (int i = 0; i < N - 1; i++) {
    for (int j = 0; j < _①_; j++) {
        if (a[j] > a[j+1]) swap(a[j], a[j+1]);
    }
}

{{ select(8) }}

  • N - i - 1
  • i - 1
  • i
  • N

第9题

下列C++代码中哪个语句运行结果是7?

{{ select(9) }}

  • cout << (char)7;
  • cout << int(4.3333333 + 2.6666666);
  • cout << 66 / 9;
  • cout << 15 / 2.0;

第10题

输入一个DNA序列:由字符A、C、G和T组成的字符串。补充下列代码找到最长的连续相同字符子串。

string s;
cin >> s;
int len = _①_, ans = 1;
for (int i = _②_; i < s.size(); i++) {
    if (s[i] == s[_③_]) len++;
    else len = 1;
    if (_④_) ans = len;
}
cout << ans;

{{ select(10) }}

  • 1, 1, i-1, len > ans
  • 0, 0, i+1, len > ans
  • 1, 1, i-1, len < ans
  • 0, 0, i+1, len < ans

第11题

想要打印等腰三角形,输入 n=4 时,输出如下:

*
* *
*  *
*   *
*  *
* *
*

代码空白处应该填入?

int n;
cin >> n;
for (int i = 1; i <= n; i++) {
    if (i == 1) cout << "*" << endl;
    else {
        cout << "*";
        for (int j = 1; j <= i - 2; j++) cout << " ";
        cout << "*" << endl;
    }
}
for (int i = _①_; i >= 1; i--) {
    if (i == _②_) cout << "*" << endl;
    else {
        cout << "*";
        for (int j = 1; j <= i - 2; j++) cout << " ";
        cout << "*" << endl;
    }
}

{{ select(11) }}

  • n - 1, n - 1
  • n, n - 1
  • n, 1
  • n - 1, 1

第12题

从一个2×2网格的左上角出发,若只允许向右或向下移动,恰好有6条路径可以到达右下角。补全以下代码,计算对于9×9的网格,有多少条路径可以到达右下角?

int g[10][10] = {};
_①_;
for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
        if (i - 1 >= 0) g[i][j] += g[i-1][j];
        _②_ g[i][j] += g[i][j-1];
    }
}
cout << g[9][9];

{{ select(12) }}

  • g[0][0] = 1, if (j - 1 >= 0)
  • g[1][1] = 1, if (j - 1 >= 0)
  • g[0][0] = 1, else if (j - 1 >= 0)
  • g[1][1] = 1, else if (j - 1 >= 0)

第13题

n 个人,第 i 个人的当前头发长度为 L[i](1 ≤ i ≤ N)。每个人的头发每天增长1。请计算并输出从第一天开始,第一次出现头发长度至少为 t 的人数 ≥ p 是第几天?

int n, t, p, L[100], cnt;
cin >> n >> t >> p;
for (int i = 0; i < n; i++) cin >> L[i];
for (int i = 1; i < t; i++) {
    cnt = 0;
    for (int j = 0; j < n; j++) {
        if (_①_) cnt++;
    }
    if (_②_) {
        cout << i << endl;
        break;
    }
}

{{ select(13) }}

  • L[i] + j >= t, cnt >= p
  • L[j] + i > t, cnt > p
  • L[j] + i >= t, cnt >= p
  • L[i] + j > t, cnt > p

第14题

执行下列程序,输出结果为?

#include <iostream>
using namespace std;
int main() {
    int i = 1, j = 1;
    int x = i++, y = ++j;
    cout << i << " " << j << " " << x << " " << y;
    return 0;
}

{{ select(14) }}

  • 1 2 2 1
  • 2 2 1 2
  • 1 2 2 2
  • 2 2 2 2

第15题

补全下列代码,计算 n(1 ≤ n ≤ 1×10⁹)的阶乘中后缀0的个数。

提示:n! 中每个后缀0都是由一个因子2和一个因子5相乘得到的,而在阶乘中因子2的个数远多于因子5的个数,因此只需统计因子5的个数。

int n, i = _①_, ans = 0;
cin >> n;
while (_②_) {
    i *= 5;
    ans += _③_;
}
cout << ans;

{{ select(15) }}

  • 5, i <= n, i
  • 1, i <= n / 5, n / i
  • 1, i < n / 5, n / i
  • 5, i < n, i

二、判断题(每题5分,共5题,25分)

第16题

C++中,逻辑与 && 的优先级高于逻辑或 ||,因此 true || false && true 等价于 true || (false && true)

{{ select(16) }}

  • 正确
  • 错误

第17题

ASCII码表中,所有数字字符('0'到'9')是连续的。

{{ select(17) }}

  • 正确
  • 错误

第18题

string s = "bcd"; s[0] = 'a'; 可以正确将 s 的第一个字符赋值为 'a'

{{ select(18) }}

  • 正确
  • 错误

第19题

结构体 struct 中只能包含成员变量和成员函数,不能包含结构体类型的变量。

{{ select(19) }}

  • 正确
  • 错误

第20题

定义 int a[3][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; 后,执行 swap(a[1][2], a[2][2]); 可以正常运行,并且执行 cout << a[2][2]; 时,程序会输出6。

{{ select(20) }}

  • 正确
  • 错误