EXY-SC-0176
第 1331 题
下面的函数 selectTopK() 实现从 n 个学生中选出前 k 名成绩最好的学生颁发奖学金(不需要对所有学生完全排序,只需要找出前 k 名),则横线上应填写( )。
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;
}
}
}
语言:
C++
GESP真题
四级
2025.12
单选题号:
11
EXY-SC-0175
第 1332 题
对如下 4 个扑克牌进行排序,
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'},则这个排序算法是稳定的吗?
语言:
C++
GESP真题
四级
2025.12
单选题号:
10
EXY-SC-0174
第 1333 题
给定函数 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;
}
语言:
C++
GESP真题
四级
2025.12
单选题号:
9
EXY-SC-0173
第 1334 题
运行如下代码会输出( )。
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;
}
语言:
C++
GESP真题
四级
2025.12
单选题号:
8
EXY-SC-0172
第 1335 题
执行完下面的代码后,a、b 和 c 的值分别是( )。
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;
}
语言:
C++
GESP真题
四级
2025.12
单选题号:
7
当前页显示 1331 - 1335
,共 1506 道单选题