#1694. GESP-C++二级(2026-09)

GESP-C++二级(2026-09)

CCF GESP C++ 二级 (2026 年 09 月)

一、单选题(每题 2 分,共 30 分)

1. 第⼆届世界⼈形机器⼈运动会开幕式上,机器⼈⽅阵通过控制程序来完成整场表演。表演前,⼯程师们使⽤ 集成开发环境(IDE)编写并调试⽅阵的控制程序。下列关于 IDE 功能的描述,错误的是( )。

{{ select(1) }}

  • 可以提供代码⾃动补全,提⾼编程效率
  • 可以提供辅助信息,帮助排查程序逻辑错误
  • 可以直接控制机器⼈电机转动
  • ⽀持语法⾼亮,使代码更易阅读

2. 计算机 CPU 中的⾼速缓冲存储器(Cache)主要为提升系统性能⽽设计。下列关于 Cache 的说法中正确的是 ( )。

{{ select(2) }}

  • Cache 的容量⽐主存⼤,速度⽐主存快
  • Cache 通常⽤于暂存 CPU 频繁访问的数据
  • Cache 中的数据断电后不会丢失,属于⾮易失性存储器
  • Cache 的访问速度⽐ CPU 寄存器还要快

3. 执⾏如下 C++ 代码,其输出是( )

cout << (3 == 3.0);

{{ select(3) }}

  • 1
  • 1.0
  • 0
  • -1

4. 执⾏如下 C++ 代码,其输出是( )

cout << (bool(5) + bool(-5) + bool(5.0));

{{ select(4) }}

  • 0
  • 1
  • 2
  • 3

5. 判断年份 N 是否为闰年的规则是:能被 4 整除但不能被 100 整除,或者能被 400 整除。以下 C++ 表达 式中,能正确判断 N 是否为闰年的是( )。

{{ select(5) }}

  • (N % 4 == 0 && N % 100 != 0) || (N % 400 == 0)
  • N % 4 == 0 && N % 100 == 0 || N % 400 == 0
  • (N / 4 == 0 && N / 100 != 0) || (N / 400 == 0)
  • (N % 4 == 0 && N % 100 != 0) && (N % 400 == 0)

6. 执⾏如下 C++ 代码,其输出是( )

int tot, i;
tot = 0;
for (i = 0; i < 10; i++)
if (i)
tot += 1;
cout << tot;

{{ select(6) }}

  • 0
  • 8
  • 9
  • 10

7. 执⾏如下 C++ 代码,当输⼊ 4 时,其输出是( )

int n, tot, i, j;
cin >> n;
tot = 0;
for (i = 1; i < n; i++)
for (j = 1; j < i; j++)
tot += 1;
cout << tot;

{{ select(7) }}

  • 1
  • 3
  • 6
  • 10

8. 下⾯的 C++ 代码执⾏后其输出是( )

int tnt, i;
tnt = 0;
for (i = 0; i < 10; i++)
if (i % 3)
tnt += i;
cout << tnt;

{{ select(8) }}

  • 12
  • 18
  • 22
  • 27

9. 下⾯的 C++ 代码之后的输出是( )

/ 10
int tot = 0, i;
for (i = -5; i < 5; i++)
if (not(i % 3 != 0))
tot += 1;
cout << tot;

{{ select(9) }}

  • 2
  • 3
  • 7
  • 9

10. 有关如下 C++ 代码描述,变量都是整型,错误的是( )

int n, limit, i;
cout << "请输入一个正整数: ";
cin >> n;
if (n <= 1)
printf("%d非素数", n);
else if (n == 2)
printf("2是素数");
else {
limit = sqrt(n) + 1;
for (i = 2; i < limit; i++)
if (n % i == 0) {
printf("%d非素数", n);
break;
}
if (i >= limit)
printf("%d是素数", n);
}

{{ select(10) }}

  • n <= 1 条件⽤于判断输⼊ 0 、 1 以及负数时的情况,不能省略。
  • n == 2 条件及其相关代码省略,程序的输出结果没有区别。
  • break 语句不可以省略,否则⾮素数还将执⾏最后⼀⾏的语句。
  • limit = sqrt(n) + 1 语句中的 1 可以修改为其他⼤于等于 1 的正整数,执⾏结果不会有错误,但循环

11. 执⾏以下 C++ 代码后,最终的输出结果是( )

int total, i, j;
total = 0;
i = 1;
while (i <= 3) {
for (j = 1; j < i + 1; j++)
total += i * j;
i += 1;
}
cout << total;

{{ select(11) }}

  • 9
  • 11
  • 23
  • 25

12. 下⾯ C++ 代码执⾏后其输出是( )

/ 10
int count, i, j;
count = 0;
for (i = 1; i < 4; i++)
for (j = 0; j < i; j++) {
if (j % 3 == 0)
continue;
count += 1;
if (i * j >= 2)
break;
}
printf("%d %d %d", i, j, count);

{{ select(12) }}

  • 2 3 2
  • 3 0 2
  • 4 1 2
  • 4 2 3

13. 如下的 C++ 代码执⾏时输⼊ 12 将输出如下数字图形。注意:最后⼀⾏之前没有空格。横线处应填⼊的代 码是( )。 2

i = 0;
cout << "请输入行数:";
cin >> line;
for (j = 0; j < line; j++) {
for (k = 0; k < ___________; k++) // L1
cout << " ";
for (k = 0; k < j + 1; k++) {
cout << i;
i += 1;
if (i >= 10)
i = 0;
}
cout << endl;
}

{{ select(13) }}

  • line - j - 1
  • line - j
  • line
  • line + 1

14. ⼩北的⾝⾼是 1.65 ⽶。班上有 n 个⼩朋友,⼩北想和⾝⾼最接近⾃⼰的⼈交朋友。如果有多个⼩朋友 与⼩北的⾝⾼差相同,⼩北想和其中⾝⾼较矮的第⼀个⼩朋友做朋友。横线处应该填⼊的是( )。 3 9 14

if (____________________) { // L1
min_diff = diff;
best_height = h;
}
}
cout << "小北的朋友身高为: " << best_height;

{{ select(14) }}

  • diff < min_diff || (diff == min_diff && h < best_height)
  • diff <= min_diff && h < best_height
  • diff < min_diff && h < best_height
  • diff < min_diff || h < best_height

15. ⼩北的⾝⾼是 1.65 ⽶。班上有 n 个⼩朋友,⼩北想和⾝⾼最接近⾃⼰的⼈交朋友。如果有多个⼩朋友 与⼩北的⾝⾼差相同,⼩北想和其中⾝⾼较矮的第⼀个⼩朋友做朋友。横线处应该填⼊的是( )。 3 9 13 18 27 A. B. C. D. 判断题(每题 分,共 分)

2 20
2 3 4 5 6 7 8 9 10

{{ select(15) }}

  • if (h < best_height) best_height = h;
  • if (h > best_height) best_height = h;
  • if (h > target) best_height = h;
  • if (h >= best_height) best_height = h;

二、判断题(每题 2 分,共 20 分)

1. C++ 程序执⾏ cin 或 scanf 语句时通常是使⽤键盘等输⼊设备来输⼊某个变量的值

{{ select(16) }}

2. 执⾏ C++ 语句 cout << ( 5 && 2 ); 将输出 1

{{ select(17) }}

3. C++ 表达式 2 * - '2' / 4 的值是 -1

{{ select(18) }}

4. 如下 C++ 代码执⾏后的输出是 10

int a;
a = 5;
a == +5;
cout << a;

{{ select(19) }}

5. 执⾏ C++ 代码 cout << (not not 5) 将输出 5

{{ select(20) }}

6. 下⾯ C++ 代码执⾏后将输出 369


for (int i = 1; i < 10; i++)
    if (not(i % 3))
        cout << i;

{{ select(21) }}

7. N 是整数,执⾏如下 C++ 代码,将能输出 0 到 N 之间(包含 N )所有数之和


int N, tot, i;
cin >> N;
tot = 0;
for (i = 0; i < N + 1; i++)
    tot += i;
cout << tot;

{{ select(22) }}

8. 如下 C++ 代码执⾏后,输出值为 0

int cnt, i, j;
cnt = 0;
for (i = 0; i < 10; i++) {
    continue;
    for (j = 0; j < i; j++)
        cnt += 1;
}
cout << i * cnt;

{{ select(23) }}

9. 求解鸡兔同笼。在如下 C++ 代码中, tou 代表鸡和兔的头总数, jiao 代表鸡和兔的脚总数。先后两个输 ⼊均为正整数。该程序能求解鸡兔同笼。 2 7


int tou, jiao, tu_tou, ji_tou;

cout << "请输入鸡和兔的头总数:";
cin >> tou;
cout << "请输入鸡和兔的脚总数:";
cin >> jiao;

for (tu_tou = 0; tu_tou < tou + 1; tu_tou++) {
    ji_tou = tou - tu_tou;
    if (tu_tou * 4 + ji_tou * 2 == jiao)
        printf("兔的数量=%d,鸡的数量=%d\n", tu_tou, ji_tou);
}
if (tu_tou == tou)
    printf("无解\n");

{{ select(24) }}

10. 如果 N 和 M 均为整数,下列 C++ 代码则可以判断正整数 N 是 M 的平⽅。####

int N, M;
cout << "请输入正整数N:";
cin >> N;
cout << "请输入整数M:";
cin >> M;
if (int(sqrt(N)) == abs(M))
    printf("%d是%d的平方\n", N, M);

{{ select(25) }}