#1033. GESP C++ 三 级 2025年3月真题 · 单选题

GESP C++ 三 级 2025年3月真题 · 单选题

GESP C++ 三 级 2025年3月真题(120 分钟,总分 100 分)

单选题(共 15 题,每题 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.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. 下面程序是将十进制转十六进制,横线处应该填入的是( )

#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;
}

{{ select(14) }}

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

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

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)