#3230. CSP-J 第一轮 入门级 C++ 语言试题(模拟卷 B)
CSP-J 第一轮 入门级 C++ 语言试题(模拟卷 B)
2026 CCF CSP-J 第一轮 入门级 C++ 语言试题(模拟卷 B)
一、单项选择题(共15题,每题2分,共计30分)
1. 1MB 等于( )字节。
{{ select(1) }}
- 1000000
- 1048576
- 1024000
- 1000000000
2. 将二进制数 101101 转换为十进制数,结果是( )。
{{ select(2) }}
- 43
- 44
- 45
- 46
3. 从 8 名同学中选出 3 人组成代表队(不区分职务),共有( )种不同的选法。
{{ select(3) }}
- 56
- 112
- 336
- 84
4. 已知字符 '0' 的 ASCII 码为 48,则字符 '5' 的 ASCII 码是( )。
{{ select(4) }}
- 5
- 48
- 53
- 52
5. 在一个有 n 个顶点的无向图中,所有顶点的度数之和等于( )。
{{ select(5) }}
- 图的边数
- 图的边数的两倍
- 图的顶点数
- 图的顶点数的两倍
6. 在 32 位系统中,表达式 sizeof(int) 的值通常为( )。
{{ select(6) }}
- 1
- 2
- 4
- 8
7. 表达式 6 & 3 的值是( )。
{{ select(7) }}
- 1
- 2
- 3
- 6
8. 链表不具有的特点是( )。
{{ select(8) }}
- 可随机访问任一元素
- 不必事先估计存储空间
- 插入删除不需要移动元素
- 所需空间与线性表长度成正比
9. 对 n 个数进行冒泡排序,在最坏情况下需要比较( )次。
{{ select(9) }}
10. 具有 3 个结点的二叉树有( )种不同的形态。
{{ select(10) }}
- 3
- 4
- 5
- 6
11. 设 x = true,y = false,z = true,则表达式 (x && y) || (!y && z) 的值是( )。
{{ select(11) }}
- true
- false
- 不确定
- 编译错误
12. 已知一棵二叉树的前序遍历为 A B C D E F,中序遍历为 C B A E D F,则其后序遍历为( )。
{{ select(12) }}
C B E F D AC B F E D AB E C F D AC E B F D A
13. 在有序数组 {2, 5, 8, 12, 16, 23, 38, 56, 72, 91} 中使用二分查找法查找元素 23,需要比较( )次才能找到。
{{ select(13) }}
- 2
- 3
- 4
- 5
14. 5 个人站成一排拍照,甲不能站在两端。共有( )种不同的排列方式。
{{ select(14) }}
- 48
- 60
- 72
- 96
15. 以下哪个不是操作系统?( )
{{ select(15) }}
- Linux
- Windows
- Oracle
- macOS
二、阅读程序
程序输入不超过数组或字符串定义的范围;判断题正确填 √,错误填 ×;除特殊说明外,判断题 1.5 分,选择题 3 分,共计 40 分。
程序 1
#include <iostream>
using namespace std;
int main() {
int n, sum = 0;
cin >> n;
while (n > 0) {
sum += n % 10;
n /= 10;
}
cout << sum << endl;
return 0;
}
判断题
16. (1.5 分)该程序的功能是计算整数 n 的各位数字之和。( )
{{ select(16) }}
- √
- ×
17. (1.5 分)当输入为 12345 时,程序的输出为 15。( )
{{ select(17) }}
- √
- ×
18. (1.5 分)当输入为 10000 时,程序的输出为 0。( )
{{ select(18) }}
- √
- ×
19. (1.5 分)当输入为 0 时,程序的输出也为 0。( )
{{ select(19) }}
- √
- ×
选择题
20. (3 分)当输入为 9876 时,程序的输出为( )。
{{ select(20) }}
- 28
- 29
- 30
- 31
21. (3 分)当输入为 999999 时,程序的输出为( )。
{{ select(21) }}
- 45
- 54
- 63
- 72
程序 2
#include <iostream>
using namespace std;
int main() {
int n, a[100];
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
int cnt = 0;
for (int i = 0; i < n - 1; i++) {
int min_idx = i;
for (int j = i + 1; j < n; j++) {
if (a[j] < a[min_idx]) {
min_idx = j;
}
}
if (min_idx != i) {
swap(a[i], a[min_idx]);
cnt++;
}
}
cout << cnt << endl;
return 0;
}
判断题
22. (1.5 分)该程序实现的是选择排序算法。( )
{{ select(22) }}
- √
- ×
23. (1.5 分)当输入为 "5\n1 2 3 4 5"(数组已按升序排列)时,cnt 的输出为 0。( )
{{ select(23) }}
- √
- ×
24. (1.5 分)当输入为 "5\n5 4 3 2 1"(数组按降序排列)时,cnt 的输出为 5。( )
{{ select(24) }}
- √
- ×
选择题
25. (3 分)当输入为 "6\n3 1 4 1 5 9" 时,cnt 的输出为( )。
{{ select(25) }}
- 2
- 3
- 4
- 5
26. (3 分)该程序的时间复杂度为( )。
{{ select(26) }}
27. (3 分)若将 if (a[j] < a[min_idx]) 改为 if (a[j] > a[min_idx]),程序的功能变为( )。
{{ select(27) }}
- 将数组从小到大排序
- 将数组从大到小排序
- 计算数组的最小值
- 程序功能不变
程序 3
#include <iostream>
using namespace std;
int hanoi(int n) {
if (n == 1) return 1;
return 2 * hanoi(n - 1) + 1;
}
int main() {
int n;
cin >> n;
cout << hanoi(n) << endl;
return 0;
}
判断题
28. (1.5 分)该程序计算的是汉诺塔问题中移动 n 个盘子所需的最少移动步数。( )
{{ select(28) }}
- √
- ×
29. (1.5 分)当输入为 3 时,程序的输出为 7。( )
{{ select(29) }}
- √
- ×
30. (1.5 分)对于任意正整数 n,hanoi(n) 的结果等于 。( )
{{ select(30) }}
- √
- ×
选择题
31. (3 分)当输入为 5 时,程序的输出为( )。
{{ select(31) }}
- 15
- 31
- 63
- 127
32. (3 分)当输入为 10 时,程序的输出为( )。
{{ select(32) }}
- 511
- 1023
- 2047
- 1024
33. (3 分)若将第 6 行改为 return 2 * hanoi(n - 1);(去掉 + 1),当输入为 4 时,程序的输出为( )。
{{ select(33) }}
- 4
- 8
- 15
- 16
三、完善程序(单选题,每小题 3 分,共计 30 分)
程序 1:快速幂
给定两个正整数 a 和 b,计算 的值。试补全程序。
#include <iostream>
using namespace std;
long long qpow(long long a, long long b) {
long long res = 1;
while (b > 0) {
if (①) {
res = res * a;
}
a = a * a;
b = ②;
}
return ③;
}
int main() {
long long a, b;
cin >> a >> b;
cout << qpow(a, b) << endl;
return 0;
}
34. (3 分)① 处应填( )。
{{ select(34) }}
b % 2 == 1b % 2 == 0b > 1a % 2 == 1
35. (3 分)② 处应填( )。
{{ select(35) }}
b--b /= 2b++b = b - 2
36. (3 分)③ 处应填( )。
{{ select(36) }}
aresba * res
37. (3 分)当输入为 "2 10" 时,程序的输出为( )。
{{ select(37) }}
- 20
- 512
- 1024
- 2048
38. (3 分)该算法的时间复杂度为( )。
{{ select(38) }}
程序 2:判断回文字符串
给定一个字符串 s,判断它是否为回文字符串(正读和反读都一样的字符串)。若是则输出
"YES",否则输出"NO"。试补全程序。
#include <iostream>
#include <string>
using namespace std;
bool isPalindrome(string s) {
int left = 0, right = ①;
while (left < right) {
if (s[left] != s[right]) {
return ②;
}
left++;
③;
}
return ④;
}
int main() {
string s;
cin >> s;
if (isPalindrome(s)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
39. (3 分)① 处应填( )。
{{ select(39) }}
s.length()s.length() - 1s.length() - 20
40. (3 分)② 处应填( )。
{{ select(40) }}
truefalse01
41. (3 分)③ 处应填( )。
{{ select(41) }}
left--left++right--right++
42. (3 分)④ 处应填( )。
{{ select(42) }}
truefalses[left] == s[right]0
43. (3 分)当输入为 "abcba" 时,程序的输出为( )。
{{ select(43) }}
- YES
- NO
- 编译错误
- 程序无限循环
Statistics
Related
In following contests: