#GESP202503C3T1. 单选题(每题 2 分,共 30 分)

    ID: 3420 Type: Objective Tried: 23 Accepted: 5 Difficulty: 2 Uploaded By: Tags>GESP三级计算机基础程序设计基础数组字符串进制转换

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

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

第 1 题

Base64 编码将每 3 字节的输入数据编码为 4 字节的输出数据。如果输入数据长度不是 3 的倍数,会用 = 号填充。在 Base64 编码中,如果输入字符串的长度为 10 字节,编码后的字符串长度是多少( )

{{ select(1) }}

  • 12 字节
  • 13 字节
  • 14 字节
  • 16 字节

第 2 题

UTF-8 编码规则如下:

1 字节:0xxxxxxx

2 字节:110xxxxx 10xxxxxx

3 字节:1110xxxx 10xxxxxx 10xxxxxx

4 字节:11110xxx 10xxxxxx 10xxxxxx 10xxxxxx

以下哪个字节序列是合法的 UTF-8 编码( )

{{ select(2) }}

  • 0xC0 0x80
  • 0xF0 0x90 0x80 0x80
  • 0x80 0x80 0x80
  • 0xFF 0xFE 0xFD

第 3 题

在 8 位二进制原码表示中,八进制数 -5 的二进制形式是什么( )

{{ select(3) }}

  • 10000101
  • 11111010
  • 11111011
  • 00000101

第 4 题

十进制数 111.111111.111 的二进制表示可以是下面的( )。

{{ select(4) }}

  • 1101111.0001110001
  • 1101110.1001110001
  • 1101111.1001110001
  • 1101111.0011110001

第 5 题

在 C++ 中,补码的主要作用是( )

{{ select(5) }}

  • 提高浮点数的精度
  • 简化整数的加减法运算
  • 增加整数的表示范围
  • 优化内存分配

第 6 题

在 C++ 中,一个 8 位有符号整数(使用补码表示)的范围是( )

{{ select(6) }}

  • -128 到 127
  • -127 到 128
  • -256 到 255
  • 0 到 255

第 7 题

在 C++ 中,以下代码的输出是什么( )

int a = -5;
unsigned int b = a;
cout << b;

{{ select(7) }}

  • -5
  • 5
  • 4294967291
  • 编译错误

第 8 题

下列程序的作用是( )

int main() {
    int decimal = 25;
    cout << oct << decimal;
    return 0;
}

{{ select(8) }}

  • 将十进制数转换成八进制数
  • 将八进制数转换成十进制数
  • 将二进制数转换成八进制数
  • 将八进制数转换成 16 进制数

第 9 题

下面程序目的是将十进制数 255 转换为十六进制输出,横线处应填写的语句是( )

#include <iostream>
using namespace std;

int main() {
    int decimal = 255;
    _______________________
    return 0;
}

{{ select(9) }}

  • cout << oct << decimal;
  • cout << decimal << decimal;
  • cout << hex << decimal;
  • 不能正确执行

第 10 题

以下代码的说法正确的是什么( )

#include <iostream>
using namespace std;

int main() {
    int a = 0b1101;
    int b = 0b1011;
    cout << (a ^ b);
    return 0;
}

{{ select(10) }}

  • 进行的是整体异或运算
  • 进行的是按位同或运算
  • 进行的是按位与运算
  • 进行的是按位异或运算

第 11 题

下面枚举法查找最大值索引程序中,横线处应该填写的是( )

#include <iostream>
using namespace std;

int main() {
    int arr[] = {3, 7, 2, 9, 5};
    int maxIndex = 0;
    for (int i = 1; i < 5; i++) {
        _______________________
        {
            maxIndex = i;
        }
    }
    cout << maxIndex;
    return 0;
}

{{ select(11) }}

  • if (arr[maxIndex] > arr[i])
  • if (arr[i]-1 > arr[maxIndex])
  • if (arr[i]+1 > arr[maxIndex])
  • if (arr[i] > arr[maxIndex])

第 12 题

以下代码的功能是将数组中的奇数和偶数分别放在数组的前半部分和后半部分,横线处应该填入的是( )

#include <iostream>
using namespace std;

int main() {
    int arr[] = {1, 2, 3, 4, 5};
    int left = 0, right = 4;
    while (left < right) {
        while (arr[left] % 2 == 1 && left < right) left++;
        _______________________
        if (left < right) {
            swap(arr[left], arr[right]);
        }
    }
    for (int i = 0; i < 5; i++) {
        cout << arr[i] << " ";
    }
    return 0;
}

{{ select(12) }}

  • while (arr[left] % 2 == 0 && left < right) right--;
  • while (arr[right] % 2 == 0 && left < right) left--;
  • while (arr[right] % 2 != 0 && left < right) right--;
  • while (arr[right] % 2 == 0 && left < right) right--;

第 13 题

下面程序最后能够得到 HelloC++ 的是( )

int main() {
    string str = "HelloWorld";
    _______________________
    cout << str;
    return 0;
}

{{ select(13) }}

  • str.replace(0, 5, "C++");
  • str.replace(5, 5, "C++");
  • str.replace(1, 5, "C++");
  • str.replace(4, 5, "C++");

第 14 题

想要得到字符串 world,下面程序横线处应该填入的是()

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

int main() {
    string str = "HelloC++";
    _____________
    _____________
    return 0;
}

A.

str.insert(4, "World");
cout << str.substr(4, 4);

B.

cout << str.substr(5, 5);

C.

str.insert("World");
cout << str.substr(5, 5);

D.

str.insert(5, "World");
cout << str.substr(5, 5);

{{ select(14) }}

  • A
  • B
  • C
  • D

第 15 题

nn 个正整数,假设一个正整数是美丽数字当且仅当该正整数是 9 的倍数但不是 8 的倍数。下面的程序是编写计算 nn 个正整数中美丽数字的数量,横线处应该填入的是( )

for (int i = 1; i <= n; i++) {
    cin >> a;
    _______________________
    cnt++;
}

{{ select(15) }}

  • if (a % 9 != 0 && a % 8 != 0)
  • if (a % 9 == 0 && a % 8 == 0)
  • if (a % 9 == 0 && a % 8 != 0)
  • if (a % 9 == 0 & a % 8 != 0)