一、单项选择题(1~15 题,每题 2 分,共 30 分)
- 在C++中,下面哪个关键字用于声明一个变量,其值不能被修改? ( )
{{ select(1) }}
- unsigned
- const
- static
- mutable
- 八进制数 12345670(8) 和 07654321(8) 的和为( )
{{ select(2) }}
- 222222218
- 211111118
- 221111118
- 222222118
- 阅读下述代码,请问修改data的value成员以存储3.14,正确的方式是() union Data {int num;float value;char symbol;};union Data data;union Data {int num;float value;char symbol;};union Data data;
{{ select(3) }}
- data.value = 3.14;
- value.data = 3.14;
- data->value = 3.14;
- value->data = 3.14;
- 假设有一个链表的节点定义如下:
struct Node { int data; Node* next; };
现在有一个指向链表头部的指针:Node* head。如果想要在链表中插入一个新的节点,其成员 data 的值为 42,并使新节点成为链表的第一个节点,下面哪个操作是正确的?
{{ select(4) }}
- Node* newNode = new Node; newNode->data = 42; newNode->next = head; head = newNode;
- Node* newNode = new Node; head->data = 42; newNode->next = head; head = newNode;
- Node* newNode = new Node; newNode->data = 42; head->next = newNode;
- Node* newNode = new Node; newNode->data = 42; newNode->next = head;
- 根节点的高度为1,一棵拥有2023个节点的三叉树高度至少为()
{{ select(5) }}
- 小明在某一天中依次有七个空闲时间段,他想要选出至少一个空闲时间段来练习唱歌,但他希望任意两个练习的时间段之间都有至少两个空闲的时间段让他休息。则小明一共有( ) 种选择时间段的方案
{{ select(6) }}
- 以下关于高精度运算的说法错误的是( )。
{{ select(7) }}
- 高精度计算主要是用来处理大整数或需要保留多位小数的运算。
- 大整数除以小整数的处理的步骤可以是,将被除数和除数对齐,从左到右逐位尝试将除数乘以某个数,通过减法得到新的被除数,并累加商。
- 高精度乘法的运算时间只与参与运算的两个整数中长度较长者的位数有关。
- 高精度加法运算的关键在于逐位相加并处理进位。
- 后缀表达式“6 2 3 + - 3 8 2 / + * 2 3 +”对应的中缀表达式是( )。
{{ select(8) }}
- ((6 - (2 + 3)) * (3 + 8 / 2)) ^ 2 + 3
- 6 - 2 + 3 * 3 + 8 / 2 ^ 2 + 3
- (6 - (2 + 3)) * ((3 + 8 / 2) ^ 2) + 3
- 6 - ((2 + 3) * (3 + 8 / 2)) ^ 2 + 3
- 数 101010(2) 和 166(8) 的和为( )
{{ select(9) }}
- 10110000(二进制)
- 236(八进制)
- 158(十进制)
- A0(十六进制)
- 假设有一组字符{a,b,c,d,e,f},对应的频率分别为5%、9%、12%、13%、16%、45%。请问以下哪个选项是字符a,b,c,d,e,f分别对应的一组哈夫曼编码?( )
{{ select(10) }}
- 1111,1110,101,100,110,0
- 1010,1001,1000,011,010,00
- 000,001,010,011,10,11
- 1010,1011,110,111,00,01
- 给定一棵二叉树,其前序遍历结果为: ABDECFG,中序遍历结果为: DEBACFG。请问这棵树的正确后序遍历结果是什么?( )
{{ select(11) }}
- EDBGFCA
- EDBFGCA
- DEBGFCA
- DBEGFCA
- 考虑一个有向无环图,该图包含4条有向边:(1,2), (1,3), (2,4)和(3,4)。以下哪个选项是这个有向无环图的一个有效的拓扑排序?( ) A.4, 2, 3, 1 B.1, 2, 3, 4 C.1, 2, 4, 3 11223344D.2, 1, 3, 4
{{ select(12) }}
- 在计算机中,以下哪个选项描述的数据存储容量最小?( )
{{ select(13) }}
- 字节(byte)
- 比特(bit)
- 字(word)
- 千字节(kilobyte)
- 一个班级有10个男生和12个女生。如果要选出一个3人的小组,并且小组中必须至少包含1个女生,那么有多少种可能的组合?( )
{{ select(14) }}
- 以下哪个不是操作系统?( )
{{ select(15) }}
- Linux
- Windows
- Android
- HTML
二、阅读程序(判断题正确填 √、错误填 ×;判断题每题 1.5 分,选择题每题 3 分)
程序 1
1 | #include <iostream>
2 | #include <cmath>
3 | using namespace std;
4 | double f(double a, double b, double c) {
5 | double s = (a + b + c) / 2;
6 | return sqrt(s * (s - a) * (s - b) * (s - c));
7 | }
8 | int main() {
9 | cout.flags(ios::flxed);
10 | cout.precision(4);
11 | int a, b, c;
12 | cin >> a >> b >> c;
13 | cout << f(a, b, c) << endl;
14 | return 0;
15 | }
- (2分) 当输入为“2 2 2”时,输出为“1.7321”。( )
{{ select(16) }}
- (2分) 将第7行中的“(s - b)(s - c)”改为“(s - c)(s - b)” 不会影响程序运行的结果。( )
{{ select(17) }}
- (2分) 程序总是输出四位小数。( )
{{ select(18) }}
- 当输入为“3 4 5”时,输出为( )。
{{ select(19) }}
- “6.0000”
- “12.0000”
- “24.0000”
- “30.0000”
程序 2
1 | #include <iostream>
2 | #include <cmath>
3 | using namespace std;
4 | double f(double a, double b, double c) {
5 | double s = (a + b + c) / 2;
6 | return sqrt(s * (s - a) * (s - b) * (s - c));
7 | }
8 | int main() {
9 | cout.flags(ios::flxed);
10 | cout.precision(4);
11 | int a, b, c;
12 | cin >> a >> b >> c;
13 | cout << f(a, b, c) << endl;
14 | return 0;
15 | }
16 | #include <iostream>
17 | #include <vector>
18 | #include <algorithm>
19 | using namespace std;
20 | int f(string x, string y) {
21 | int m = x.size();
22 | int n = y.size();
23 | vector<vector<int>> v(m+1,vector<int>(n+1,0));
24 | for(int i = 1; i <= m; i++) {
25 | for(int j = 1; j <= n; j++) {
26 | if(x[i-1] == y[j-1]) {
27 | v[i][j] = v[i-1][j-1] + 1;
28 | } else {
29 | v[i][j] = max(v[i-1][j], v[i][j-1]);
30 | }
31 | }
32 | }
33 | return v[m][n];
34 | }
35 | bool g(string x, string y) {
36 | if(x.size() != y.size()) {
37 | return false;
38 | }
39 | return f(x + x, y) == y.size();
40 | }
41 | int main() {
42 | string x, y;
43 | cin >> x >> y;
44 | cout << g(x, y) << endl;
45 | return 0;
46 | }
- 当输入为“5 12 13”时,输出为( )
{{ select(20) }}
- “24.0000”
- “30.0000”
- “60.0000”
- “120.0000”
- f函数的返回值小于等于min(n,m)。( )
{{ select(21) }}
- f函数的返回值等于两个输入字符串的最长公共子串的长度。( )
{{ select(22) }}
- 当输入两个完全相同的字符串时,g函数的返回值总是true.( )
{{ select(23) }}
- 将第19行中的“v[m][n]” 替换为 “v[n][m]”,那么该程序( )。
{{ select(24) }}
- 行为不变
- 只会改变输出
- 一定非正常退出
- 可能非正常退出
- 当输入为“csp-j p-jcs”时,输出为( )。
{{ select(25) }}
程序 3
1 | #include <iostream>
2 | #include <cmath>
3 | using namespace std;
4 | double f(double a, double b, double c) {
5 | double s = (a + b + c) / 2;
6 | return sqrt(s * (s - a) * (s - b) * (s - c));
7 | }
8 | int main() {
9 | cout.flags(ios::flxed);
10 | cout.precision(4);
11 | int a, b, c;
12 | cin >> a >> b >> c;
13 | cout << f(a, b, c) << endl;
14 | return 0;
15 | }
16 | #include <iostream>
17 | #include <vector>
18 | #include <algorithm>
19 | using namespace std;
20 | int f(string x, string y) {
21 | int m = x.size();
22 | int n = y.size();
23 | vector<vector<int>> v(m+1,vector<int>(n+1,0));
24 | for(int i = 1; i <= m; i++) {
25 | for(int j = 1; j <= n; j++) {
26 | if(x[i-1] == y[j-1]) {
27 | v[i][j] = v[i-1][j-1] + 1;
28 | } else {
29 | v[i][j] = max(v[i-1][j], v[i][j-1]);
30 | }
31 | }
32 | }
33 | return v[m][n];
34 | }
35 | bool g(string x, string y) {
36 | if(x.size() != y.size()) {
37 | return false;
38 | }
39 | return f(x + x, y) == y.size();
40 | }
41 | int main() {
42 | string x, y;
43 | cin >> x >> y;
44 | cout << g(x, y) << endl;
45 | return 0;
46 | }
47 | #include <iostream>
48 | #include <cmath>
49 | using namespace std;
50 | int solve1(int n) {
51 | return n * n;
52 | }
53 | int solve2(int n) {
54 | int sum = 0;
55 | for (int i = 1; i <= sqrt(n); i++) {
56 | if(n % i == 0) {
57 | if(n/i == i) {
58 | sum += i*i;
59 | } else {
60 | sum += i*i + (n/i)*(n/i);
61 | }
62 | }
63 | }
64 | return sum;
65 | }
66 | int main() {
67 | int n;
68 | cin >> n;
69 | cout<<solve2(solve1(n))<<" "<<solve1(solve2(n))<< endl;
70 | return 0;
71 | }
- 当输入为“csppsc spsccp”时,输出为( )。
{{ select(26) }}
- 如果输入的n为正整数,solve2函数的作用是计算n所有的因子的平方和。( )
{{ select(27) }}
- 第13-14行的作用是避免n的平方根因子(或n/i)进入第16行而被计算两次。( )
{{ select(28) }}
- 如果输入的n为质数,solve2(n)的返回值为n2+1。( )
{{ select(29) }}
- (4分)如果输入的n为质数p的平方,那么solve2(n)的返回值为( )。
{{ select(30) }}
- p2 + p + 1
- n2 + n + 1
- n2 + 1
- p4 + 2p2 + 1
- (4 分)当输入为正整数时,第一项减去第二项的差值一定( )
{{ select(31) }}
- 大于等于0
- 大于等于0且不一定大于0
- 小于0
- 小于等于0且不一定小于0
- 当输入为“5”时,输出为( )。
{{ select(32) }}
- “651 625”
- “650 729”
- “651 676”
- ”652 625”
三、完善程序(每题 3 分)
程序 1
1 | #include <iostream>
2 | #include <vector>
3 | using namespace std;
4 | int find_missing(vector<int>& nums) {
5 | int left = 0, right = nums.size() - 1;
6 | while (left < right) {
7 | int mid = left + (right - left) / 2;
8 | if (nums[mid] == mid + ①) {
9 | ②
10 | } else {
11 | ③
12 | }
13 | }
14 | return ④
15 | }
16 | int main() {
17 | int n;
18 | cin >> n;
19 | vector<int> nums(n);
20 | for(int i = 0; i < n; i++)cin >> nums[i];
21 | int missing_number = find_missing(nums);
22 | if (missing_number == ⑤) {
23 | cout << "Sequence is consecutive" << endl;
24 | } else {
25 | cout << "Missing number is " << missing_number << endl;
26 | }
27 | return 0;
28 | }
- ①处应该填( )
{{ select(33) }}
- ②处应该填( )
{{ select(34) }}
- left = mid + 1
- right = mid - 1
- right = mid
- left = mid
- ③处应该填( )
{{ select(35) }}
- left = mid + 1
- right = mid - 1
- right = mid
- left = mid
- ④处应该填( )
{{ select(36) }}
- left = nums[0]
- right + nums[0]
- mid + nums[0]
- right + 1
- ⑤处应该填( )
{{ select(37) }}
- nums[0]+n
- nums[0]+n-1
- nums[0]+n+1
- nums[n-1]
程序 2
1 | #include <iostream>
2 | #include <string>
3 | #include <vector>
4 | using namespace std;
5 | int min(int x, int y, int z) {
6 | return min(min(x, y), z);
7 | }
8 | int edit_dist_dp(string str1, string str2) {
9 | int m = str1.length();
10 | int n = str2.length();
11 | vector<vector<int>> dp(m + 1, vector<int>(n + 1));
12 | for (int i = 0; i <= m; i++) {
13 | for (int j = 0; j <= n; j++) {
14 | if (i == 0)
15 | dp[i][j] = ①;
16 | else if (j == 0)
17 | dp[i][j] = ②;
18 | else if (③)
19 | dp[i][j] = ④;
20 | else
21 | dp[i][j]=1+min(dp[i][j - 1],dp[i - 1][j], ⑤);
22 | }
23 | }
24 | return dp[m][n];
25 | }
26 | int main() {
27 | string str1, str2;
28 | cin >> str1 >> str2;
29 | cout << "Mininum number of operation:"
30 | << edit_dist_dp(str1, str2) << endl;
31 | return 0;
32 | }
- ①处应该填( )
{{ select(38) }}
- ②处应该填( )
{{ select(39) }}
- ③处应该填( )
{{ select(40) }}
- str1[i - 1] == str2[j - 1]
- str1[i] == str2[j]
- str1[i - 1] != str2[j - 1]
- str1[i] != str2[j]
- ④处应该填( )
{{ select(41) }}
- dp[i - 1][j - 1] + 1
- dp[i - 1][j - 1]
- dp[i - 1][j]
- dp[i][j - 1]
- ⑤处应该填( )
{{ select(42) }}
- dp[i][j] + 1
- dp[i - 1][j - 1] + 1
- dp[i - 1][j - 1]
- dp[i][j]