题目编号
语言
全部语言
等级
全部等级
知识点
选择知识点 (0)
找到 1260 道单选题
EXY-SC-0480
第 781 题

运行下面的代码,屏幕上将输出( )。

#include <iostream>
using namespace std;

int divide(int a, int b) {
    if (b == 0) {
        throw runtime_error("division by zero error ");
    }
    return a / b;
}

int main() {
    int x = 10;
    int y = 0; // 设为 0 会导致除零错误
    try {
        int result = divide(x, y);
        cout << "result: " << result << endl;
    } catch (const runtime_error& e) {
        cout << "caught an exception: " << e.what() << endl;
    }
    return 0;
}
A

division by zero error result: caught an exception:

B

result: caught an exception: division by zero error

C

caught an exception: division by zero error

D

division by zero error caught an exception: division by zero error

语言: C++
GESP真题 四级
2024.9
单选题号: 15
EXY-SC-0479
第 782 题

小杨用文件重定向实现在 log.txt 文件中输出日志,则下面横线上应填写( )。

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main() {
    ofstream log_file("log.txt");
    streambuf* original_cout = cout.rdbuf();
    cout.rdbuf(log_file.rdbuf());
    ____________________    // 在此处填入代码
    cout.rdbuf(original_cout); // 恢复原始的标准输出缓冲区
    return 0;
}
A

cout << "This output will go to the log file." << endl;

B

log_file << "This output will go to the log file." << endl;

C

cout >> "This output will go to the log file." >> endl;

D

log_file >> "This output will go to the log file." >> endl;

语言: C++
GESP真题 四级
2024.9
单选题号: 14
EXY-SC-0478
第 783 题

下面代码实现了插入排序函数(升序),则横线上应填写( )。

void insertion_sort(vector<int> &nums) {
    for (int i = 1; i < nums.size(); i++) {
        int base = nums[i], j = i - 1;
        ____________________________    // 在此处填入代码
        {
            nums[j + 1] = nums[j];
            j--;
        }
        nums[j + 1] = base;
    }
}
A

while (j >= 0 && nums[j] > base)

B

while (j > 0 && nums[j] > base)

C

while (j >= 0 && nums[j] < base)

D

while (j > 0 && nums[j] < base)

语言: C++
GESP真题 四级
2024.9
单选题号: 13
EXY-SC-0477
第 784 题

上一题算法的时间复杂度为( )。

A

$O(n^2)$

B

$O(2^n)$

C

$O(1)$

D

$O(n)$

语言: C++
GESP真题 四级
2024.9
单选题号: 12
EXY-SC-0476
第 785 题

下面代码实现了冒泡排序函数,则横线上应填写( )。

//交换数组arr的第i个元素和第j个元素
void swap(vector<int> &arr, int i, int j) {
    int tmp = arr[i];
    arr[i] = arr[j];
    arr[j] = tmp;
}

int bubble_sort(vector<int> &arr) {
    for (int i = arr.size() - 1; i > 0; i--) {
        bool flag = false; // 标志位
        ____________________________    // 在此处填入代码
        {
            if (arr[j] > arr[j + 1]) {
                swap(arr, i, j);
                flag = true;
            }
        }
        if (!flag)
            break; // 此轮“冒泡”未交换任何元素
    }
}
A

for (int j = 0; j < arr.size() - 1; j++)

B

for (int j = arr.size() - 1; j > 0; j--)

C

for (int j = 0; j < i; j++)

D

for (int j = i-1; j <=0; j--)

语言: C++
GESP真题 四级
2024.9
单选题号: 11
当前页显示 781 - 785 ,共 1260 道单选题