#XSYK20260503. 信息素养初赛模拟八(初中组)
信息素养初赛模拟八(初中组)
一.单选题(每题 5 分,共 75 分)
- 请将二进制数1101.101转换为等值的10进制数( ) {{ select(1) }}
- 14.25
- 13.625
- 13.5
- 14.5
- 执行以下程序段,输出值是 ( )
int x = 5;
if (x == (3 >> 2))
x = (8 >> 3);
cout << x << endl;
{{ select(2) }}
- 0
- 5
- 120
- 1
- 以下关于 C++ 求最小值函数
min()的描述,不正确的是 ( ) {{ select(3) }}
- 函数必须返回一个值
- 该函数可以嵌套调用
- 调用
min(5)是错误的,不能通过编译 - 调用
min()(不传任何参数)可以通过编译,结果为 0
- 计算表达式
a & b | (c ^ d)的结果,其中a=3、b=7、c=15、d=4,结果是 ( ) {{ select(4) }}
- 十进制 11
- 二进制 11
- 八进制 11
- 十六进制 11
- 以下关于 C++ 中
abs()函数的描述,正确的是 ( ) {{ select(5) }}
abs()函数可用于计算int类型整数的绝对值,头文件为<cmath>或<cstdlib>- 调用
abs(3.14)可以四舍五入得到 3 abs(-1, -2)的返回值是 1- 若传入负数浮点数,
abs()会自动截断小数部分后返回整数绝对值
- 小杨想让指针
p指向整数变量x,正确写法是( ) {{ select(6) }}
int p = &x;int *p = x;int *p = &x;p = *x;
- 小杨写了如下的指针接力程序,程序执行完后变量
a、*p1和*p2的值分别是( )
int a = 5;
int* p1 = &a;
int* p2 = p1;
*p2 = 10;
{{ select(7) }}
- 5 10 10
- 5 10 15
- 10 10 10
- 5 5 10
- 执行完下面的代码后,
*(p + 5)和arr[1][1]的值分别是 ( )
int arr[3][4] = {{1,2,3,4}, {5,6,7,8}, {9,10,11,12}};
int* p = &arr[0][0];
{{ select(8) }}
- 5 6
- 6 5
- 5 5
- 6 6
- 执行完下面的代码后,输出是 ( )
int a = 1;
void test() {
int a = 2;
{
int a = 3;
a++;
}
a++;
cout << a << " ";
}
int main() {
test();
cout << a;
return 0;
}
{{ select(9) }}
- 3 1
- 4 1
- 3 2
- 4 2
- 执行完下面的代码后,
a、b和c的值分别是 ( )
void byValue(int x) { x = 100; }
void byRef(int& x) { x = 200; }
void byPointer(int* x) { *x = 300; }
int main() {
int a = 1, b = 2, c = 3;
byValue(a);
byRef(b);
byPointer(&c);
cout << a << " " << b << " " << c;
return 0;
}
{{ select(10) }}
- 100 200 300
- 1 2 3
- 1 200 300
- 1 2 300
- 运行如下代码会输出 ( )
struct Point {
int x, y;
};
struct Rectangle {
Point topLeft;
Point bottomRight;
};
int main() {
Rectangle rect = {{10, 10}, {20, 20}};
rect.topLeft.x = 5;
Point* p = &rect.bottomRight;
p->y = 5;
cout << rect.topLeft.x + rect.bottomRight.y;
return 0;
}
{{ select(11) }}
- 10
- 30
- 15
- 20
- 给定函数
climbStairs(int n)的定义如下,则climbStairs(5)的返回的值是 ( )
int climbStairs(int n) {
if(n <= 2) return n;
int a = 1, b = 2;
for(int i = 3; i <= n; i++) {
int temp = a + b;
a = b;
b = temp;
}
return b;
}
{{ select(12) }}
- 5
- 8
- 13
- 10
- 对如下 4 个扑克牌进行排序,
struct Card定义及初始数据如下。使用某排序算法按value排序后,结果为:{3,'D'}, {3,'B'}, {5,'A'}, {5,'C'},则这个排序算法是稳定的吗?( )
struct Card {
int value;
char suit; // 花色
};
Card cards[4] = {{5,'A'}, {3,'B'}, {5,'C'}, {3,'D'}};
{{ select(13) }}
- 稳定,因为相同 value 的元素相对顺序保持不变
- 不稳定,因为
{3,'D'}出现在{3,'B'}之前 - 无法判断
- 稳定,因为结果是有序的
- 下面的函数
selectTopK()实现从n个学生中选出前k名成绩最好的学生颁发奖学金(不需要对所有学生完全排序,只需要找出前k名),则横线上应填写 ( )
struct Student {
string name;
int score;
};
void selectTopK(Student students[], int n, int k) {
for (int i = 0; i < k; i++) {
int maxIdx = i;
for (____________________) { // 在此处填入代码
if (students[j].score > students[maxIdx].score) {
maxIdx = j;
}
}
if (maxIdx != i) {
Student temp = students[i];
students[i] = students[maxIdx];
students[maxIdx] = temp;
}
}
}
{{ select(14) }}
int j = 0; j < n; j++int j = i + 1; j < n; j++int j = i; j < n; j++int j = 1; j <= n; j++
- 某游戏的排行榜系统需要实时更新玩家分数。每次只有一个玩家的分数发生变化,排行榜已经是按分数降序排列的。现在需要将更新后的玩家调整到正确位置。下面的函数
updateRanking()要实现上述功能,则两处横线上应分别填写 ( )
struct Player {
string name;
int score;
};
// 玩家索引playerIdx的分数刚刚更新,需要调整位置
void updateRanking(Player players[], int size, int playerIdx) {
Player updatedPlayer = players[playerIdx];
if (playerIdx > 0 && updatedPlayer.score > players[playerIdx - 1].score) {
int i = playerIdx;
while (____________________) { // 此处填第一空
players[i] = players[i - 1];
i--;
}
players[i] = updatedPlayer;
} else if (playerIdx < size - 1 && updatedPlayer.score < players[playerIdx + 1].score) {
int i = playerIdx;
while (____________________) { // 此处填第二空
players[i] = players[i + 1];
i++;
}
players[i] = updatedPlayer;
}
}
{{ select(15) }}
- 第一空:
i > 0 && updatedPlayer.score > players[i - 1].score;第二空:i < size - 1 && updatedPlayer.score < players[i + 1].score - 第一空:
i < size - 1 && updatedPlayer.score < players[i + 1].score;第二空:i > 0 && updatedPlayer.score > players[i - 1].score - 第一空:
i > 0 && updatedPlayer.score < players[i - 1].score;第二空:i < size - 1 && updatedPlayer.score < players[i + 1].score - 第一空:
i > 0 && updatedPlayer.score < players[i - 1].score;第二空:i < size - 1 && updatedPlayer.score > players[i + 1].score
二.判断题(每题 5 分,共 25 分)
- 位运算符
&、|、^、~的优先级高于算术运算符+、-、*、/。 {{ select(16) }}
- 正确
- 错误
- 给定一个正整数
a,当需要计算-a的补码时,有这样一个计算技巧:将a的二进制形式从右往左扫描,遇到第一个 1 之后,将找到的第一个 1 左边的所有位都取反,能得到-a的补码。 {{ select(17) }}
- 正确
- 错误
- 小杨正在调试他的温度传感器程序,其中变量
x保存当前温度。下面这段代码运行后,变量x的值变成了 8。
int x = 5;
int *p = &x;
*p = *p + 3;
{{ select(18) }}
- 正确
- 错误
- 一个结构体不能包含另一个结构体。 {{ select(19) }}
- 正确
- 错误
- 执行下面程序后,变量
a的值会变成 15。
void add(int &x) {
x += 10;
}
int main() {
int a = 5;
add(a);
cout << a;
return 0;
}
{{ select(20) }}
- 正确
- 错误