EXY-SC-0495
第 766 题
运行下面的代码,将出现什么情况?( )
double hmean(double a, double b) {
if (a == -b)
throw runtime_error("Runtime error occurred");
return 2.0*a*b/(a + b);
}
int main() {
double x = 10;
double y = -10;
try {
int result = hmean(x, y);
cout << "hmean: " << result << endl;
}
catch (const runtime_error& e) {
cout << "Caught: " << e.what() << endl;
}
catch (...) {
cout << "Caught an unknown exception." << endl;
}
return 0;
}
语言:
C++
GESP真题
四级
2024.12
单选题号:
15
EXY-SC-0494
第 767 题
下面哪种方式不能实现将字符串 "Welcome to GESP!" 输出重定向到文件 log.txt( )。
语言:
C++
GESP真题
四级
2024.12
单选题号:
14
EXY-SC-0493
第 768 题
下面代码实现了插入排序函数,则横线上应填写( )。
void insertion_sort(vector<int> &nums) {
for (int i = 1; i < nums.size(); i++) {
________________________ { // 在此处填入代码
while (j >= 0 && nums[j] > base)
nums[j + 1] = nums[j];
j--;
}
nums[j + 1] = base;
}
}
语言:
C++
GESP真题
四级
2024.12
单选题号:
13
EXY-SC-0492
第 769 题
给定如下代码,其时间复杂度为( )。
int cellRecur(int n) {
if (n == 1)
return 1;
return cellRecur(n - 1) + cellRecur(n - 1) + 1;
}
语言:
C++
GESP真题
四级
2024.12
单选题号:
12
EXY-SC-0491
第 770 题
冒泡排序的第一轮操作是从左到右遍历数组,通过两两比较相邻元素,将当前最大的元素移动到末尾。给定数组 arr[]={4, 1, 3, 1, 5, 2},执行第一轮冒泡排序后数组 arr 中的内容为( )。
语言:
C++
GESP真题
四级
2024.12
单选题号:
11
当前页显示 766 - 770
,共 1260 道单选题