信奥刷题站
GESP 认证 4级2025-12

2025年12月 GESP C++ 4级

题量
27 题
客观题
25 题
建议时长
60 分钟
卷面总分
100 分

2025年12月 GESP C++ 4级认证考试真题(含编程操作题部分)

开始整卷模拟计时作答 · 交卷即时判分 · 错题自动进错题本(需登录)2 道编程大题:在线只判客观题,编程题请自行前往洛谷等 OJ 提交验证

// questions

题目预览

1
单选题2

小杨想让指针 ppp 指向整数变量 xxx,正确写法是( )。

A

int p = &x;

B

int *p = x;

C

int *p = &x;

D

p = *x;

2
单选题2

小杨写了如下的指针接⼒程序,程序执行完后变量 aaa*p1*p2 的值分别是( )。

int a = 5;
int* p1 = &a;
int* p2 = p1;
*p2 = 10;
A

555 101010 101010

B

555 101010 151515

C

101010 101010 101010

D

555 555 101010

3
单选题2

小杨用一个二维数组表示棋盘,其中 111 表示有棋子,000 表示没有棋子。他想知道第 222 行第 333 列有没有棋子,可采用的代码是:( )。

int a[3][4] = {
    {1, 0, 1, 0},
    {0, 1, 0, 1},
    {1, 1, 0, 0}
};
A

cout << a[1, 2] << endl;

B

cout << a[1][2] << endl;

C

cout << a(1, 2) << endl;

D

cout << a{1}{2} << endl;

4
单选题2

执行完下面的代码后,*(p + 5)arr[1][1] 的值分别是( )。

int arr[3][4] = {{1,2,3,4}, {5,6,7,8}, {9,10,11,12}};
int* p = &arr[0][0];
A

555 666

B

666 555

C

555 555

D

666 666

5
单选题2

执行完下面的代码后,sumsumsum 的值是( )。

int arr[2][3][2] = {
    {{1,2}, {3,4}, {5,6}},
    {{7,8}, {9,10}, {11,12}}
};
int sum = 0;
for(int i = 0; i < 2; i++)
    for(int j = 0; j < 3; j++)
        for(int k = 0; k < 2; k++)
            if((i+j+k) % 2 == 0)
                sum += arr[i][j][k];
A

363636

B

393939

C

787878

D

303030

6
单选题2

执行完下面的代码后,输出是( )。

int a = 1;
void test() {
    int a = 2;
    {
        int a = 3;
        a++;
    }
    a++;
    cout << a << " ";
}
int main() {
    test();
    cout << a;
    return 0;
}
A

3 1

B

4 1

C

3 2

D

4 2

7
单选题2

执行完下面的代码后,aaabbbccc 的值分别是( )。

void byValue(int x) { x = 100; }
void byRef(int& x) { x = 200; }
void byPointer(int* x) { *x = 300; }
int main() {
    int a = 1, b = 2, c = 3;
    byValue(a);
    byRef(b);
    byPointer(&c);
    return 0;
}
A

100100100 200200200 300300300

B

111 222 333

C

111 200200200 300300300

D

111 222 300300300

8
单选题2

运行如下代码会输出( )。

struct Point {
    int x, y;
};
struct Rectangle {
    Point topLeft;
    Point bottomRight;
};
int main() {
    Rectangle rect = {{10, 10}, {20, 20}};
    rect.topLeft.x = 5;
    Point* p = &rect.bottomRight;
    p->y = 5;
    cout << rect.topLeft.x + rect.bottomRight.y;
    return 0;
}
A

101010

B

303030

C

151515

D

202020

9
单选题2

给定函数 climbStairs(int n) 的定义如下,则 climbStairs(5) 的返回的值是( )。

int climbStairs(int n) {
    if(n <= 2) return n;
    int a = 1, b = 2;
    for(int i = 3; i <= n; i++) {
        int temp = a + b;
        a = b;
        b = temp;
    }
    return b;
}
A

555

B

888

C

131313

D

101010

10
单选题2

对如下 444 个扑克牌进行排序,

struct Card {
    int value;
    char suit; // 花色
};
Card cards[4] = {{5,'A'}, {3,'B'}, {5,'C'}, {3,'D'}};

使用某排序算法按 value 排序后,结果为: {3,'D'}, {3,'B'}, {5,'A'}, {5,'C'},则这个排序算法是稳定的吗?

A

稳定,因为相同 value 的元素相对顺序保持不变

B

不稳定,因为 {3,'D'} 出现在 {3,'B'} 之前

C

无法判断

D

稳定,因为结果是有序的

11
单选题2

下面的函数 selectTopK() 实现从 nnn 个学生中选出前 kkk 名成绩最好的学生颁发奖学金(不需要对所有学生完全排序,只需要找出前 kkk 名),则横线上应填写( )。

struct Student {
    string name;
    int score;
};
void selectTopK(Student students[], int n, int k) {
    for (int i = 0; i < k; i++) {
        int maxIdx = i;
        for (____________________) { // 在此处填入代码
            if (students[j].score > students[maxIdx].score) {
                maxIdx = j;
            }
        }
        if (maxIdx != i) {
            Student temp = students[i];
            students[i] = students[maxIdx];
            students[maxIdx] = temp;
        }
    }
}
A

int j = 0; j < n; j++

B

int j = i + 1; j < n; j++

C

int j = i; j < n; j++

D

int j = 1; j <= n; j++

12
单选题2

某游戏的排行榜系统需要实时更新玩家分数。每次只有一个玩家的分数发生变化,排行榜已经是按分数降序排列的。现在需要将更新后的玩家调整到正确位置。下面的函数 updateRanking() 要实现上述功能,则两处横线上应分别填写( )。

struct Player {
    string name;
    int score;
};
// 玩家索引 playerIdx 的分数刚刚更新,需要调整位置
void updateRanking(Player players[], int size, int playerIdx) {
    Player updatedPlayer = players[playerIdx];
    if (playerIdx > 0 && updatedPlayer.score > players[playerIdx - 1].score) {
        int i = playerIdx;
        while (____________________) { // 在此处填入代码
            players[i] = players[i - 1];
            i--;
        }
        players[i] = updatedPlayer;
    }
    else if (playerIdx < size - 1 && updatedPlayer.score < players[playerIdx + 1].score) {
        int i = playerIdx;
        while (____________________) { // 在此处填入代码
            players[i] = players[i + 1];
            i++;
        }
        players[i] = updatedPlayer;
    }
}
A
i > 0 && updatedPlayer.score > players[i - 1].score
i < size - 1 && updatedPlayer.score < players[i + 1].score
B
i < size - 1 && updatedPlayer.score < players[i + 1].score
i > 0 && updatedPlayer.score > players[i - 1].score
C
i > 0 && updatedPlayer.score < players[i - 1].score
i < size - 1 && updatedPlayer.score < players[i + 1].score
D
i > 0 && updatedPlayer.score < players[i - 1].score
i < size - 1 && updatedPlayer.score > players[i + 1].score
13
单选题2

给定如下算法,其时间复杂度为( )。

bool f(int arr[], int n, int target) {
    for (int i = 0; i < n; i++) {
        int sum = 0;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                sum += arr[j];
            }
        }
        if (sum == target) return true;
    }
    return false;
}
A
B
C
D
14
单选题2

执行下面 C++ 程序,会输出( )。

int main() {
    ofstream fout("test.txt");
    fout << "Happy" << endl;
    fout << "New Year";
    fout.close();
    ifstream fin("test.txt");
    string s1, s2;
    fin >> s1;
    getline(fin, s2);
    fin.close();
    cout << s1 << "|" << s2;
    return 0;
}
A

Happy|New Year

B

Happy| New Year

C

HappyNew Year|

D

Happy|

15
单选题2

执行下面 C++ 代码,会输出( )。

int divide(int a, int b) {
    if(b == 0) throw "Division by zero";
    return a / b;
}
int main() {
    int result = 0;
    try {
        result = divide(10, 0);
        cout << "A";
    }
    catch(const char* msg) {
        cout << "B";
        result = -1;
    }
    cout << result;
    return 0;
}
A

A0

B

B-1

C

A10

D

程序崩溃

16
判断题2

小杨正在调试他的温度传感器程序,其中变量 xxx 保存当前温度。下面这段代码运行后,变量 xxx 的值变成了 888

int x = 5;
int *p = &x;
*p = *p + 3;
17
判断题2

一个结构体不能包含另一个结构体。

18
判断题2

在 C++ 中,定义如下二维数组:int a[3][4];,数组 aaa 在内存中是按行优先连续存放的,即 a[0][0]a[0][1]a[0][2]a[0][3] 在内存中是连续的。

19
判断题2

执行下面程序后,变量 aaa 的值会变成 151515

void add(int &x){
    x += 10;
}
int a = 5;
add(a);
20
判断题2

执行下面的 C++ 代码,会输出 888 ,因为两个指针地址相差 888 个字节(假设 int444 字节)。

int arr[5] = {1, 2, 3, 4, 5};
int* p1 = arr;
int* p2 = arr + 2;
cout << p2 - p1; // 输出结果
21
判断题2

考虑用如下递推方式计算斐波那契数列,时间复杂度是 。

int n = 10;
int f[20];
f[0] = 0;
f[1] = 1;
for (int i = 2; i <= n; i++)
    f[i] = f[i - 1] + f[i - 2];
22
判断题2

冒泡排序和插入排序都是稳定排序算法。

23
判断题2

下面这段代码实现了选择排序算法。

void sort(int a[], int n) {
    for (int i = 1; i < n; i++) {
        int x = a[i];
        int j = i - 1;
        while (j >= 0 && a[j] > x) {
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = x;
    }
}
24
判断题2

下面代码可以正常编译并输出 101010

#include <iostream>
using namespace std;
int calculate(int x, int y = 10);
int main() {
    cout << calculate(5); // 调用1
    return 0;
}
int calculate(int x, int y) {
    return x * y;
}
int calculate(int x) { // 重载函数
    return x * 2;
}
25
判断题2

执行下面代码会输出 100100100

int main() {
    ofstream fout("data.txt");
    fout << 10 << " " << 20 << endl;
    fout << 30 << " " << 40;
    fout.close();
    ifstream fin("data.txt");
    int a, b, c, d;
    fin >> a >> b >> c >> d;
    fin.close();
    cout << a + b + c + d;
    return 0;
}
GESP 编程操作题
26
编程题25

试题名称:建造

时间限制:1.0 s | 内存限制:512.0 MB

题目描述

小 A 有一张 MMMNNN 列的地形图,其中第 iii 行第 jjj 列的数字 aija_{ij}aij 代表坐标 (i,j)(i, j)(i,j) 的海拔高度。

停机坪为一个 3×33 \times 33×3 的区域,且内部所有 999 个点的最大高度和最小高度之差不超过 HHH

小 A 想请你计算出,在所有适合建造停机坪的区域中,区域内部 999 个点海拔之和最大是多少。

输入格式

第一行三个正整数 M,N,HM, N, HM,N,H,含义如题面所示。

之后 MMM 行,第 iii 行包含 NNN 个整数 ai1,ai2,…,aiNa_{i1}, a_{i2}, \dots, a_{iN}ai1,ai2,,aiN,代表坐标 (i,j)(i, j)(i,j) 的高度。

数据保证总存在一个适合建造停机坪的区域。

输出格式

输出一行,代表最大的海拔之和。

样例输入 #1

5 5 3
5 5 5 5 5
5 1 5 1 5
5 5 5 5 5
5 2 5 2 5
3 5 5 5 2

样例输出 #1

40

说明/提示

数据范围

对于所有测试点,保证 1≤M,N≤1031 \leq M, N \leq 10^31M,N1031≤H,aij≤1051 \leq H, a_{ij} \leq 10^51H,aij105

本题为编程大题:请复制题面到洛谷 / GESP OJ 等平台编写并提交代码(本站不判分)
27
编程题25

试题名称:优先购买

时间限制:1.0 s | 内存限制:512.0 MB

题目描述

小 A 有 MMM 元预算。商店有 NNN 个商品,每个商品有商品名 SSS、价格 PPP 和优先级 VVV 三种属性,其中 VVV 为正整数,且 VVV 越小代表商品的优先级越高。

小 A 的购物策略为:

  • 总是优先买优先级最高的东西;
  • 如果有多个最高优先级商品,购买价格最低的;
  • 如果有多个优先级最高且价格最低的商品,购买商品名字典序最小的。

小 A 想知道能购买哪些商品。

输入格式

第一行两个正整数 M,NM, NM,N,代表预算和商品数。

之后 NNN 行,每行一个商品,依次为 Si Pi ViS_i\ P_i\ V_iSi Pi Vi,代表第 iii 个商品的商品名、价格、优先级。

数据保证不存在两个名字相同的商品。

输出格式

按照字典序从小到大的顺序,输出所有购买商品的商品名。

样例输入 #1

20 4
apple 6 8
bus 15 1
cab 1 10
water 4 8

样例输出 #1

bus
cab
water

说明/提示

数据范围

对于所有测试点,保证 1≤∣Si∣≤101 \leq |S_i| \leq 101Si101≤M,Pi≤1051 \leq M, P_i \leq 10^51M,Pi1051≤N≤1031 \leq N \leq 10^31N1031≤Vi≤101 \leq V_i \leq 101Vi10。商品名仅由小写字母组成且不存在两个相同的商品名。

本题为编程大题:请复制题面到洛谷 / GESP OJ 等平台编写并提交代码(本站不判分)