#4642. 信息素养智汇少年挑战赛初赛试卷二(初)
信息素养智汇少年挑战赛初赛试卷二(初)
一、单选题(共28题,每题2分,共56分)
- 执行以下代码后,输出结果是()
#include <iostream>
using namespace std;
int main() {
int a=3, b=5;
cout << (a>b?a++:b++) << " " << a << " " << b << endl;
return 0;
}
{{ select(1) }}
- 3 3 6
- 5 3 6
- 3 4 5
- 5 4 5
- 以下关于文件读写的说法,错误的是()
{{ select(2) }}
- 使用ios::binary模式可以读写二进制文件
- getline()函数可以读取包含空格的一行字符串
- 以ios::out模式打开已存在的文件会清空原有内容
- ifstream对象可以直接用>>运算符读取整数和字符串
- 执行以下代码后,变量x的值是()
int x=20;
if(x>10)
if(x>15) x=30;
else if(x>20) x=40;
else x=50;
{{ select(3) }}
- 20
- 30
- 40
- 50
- 以下代码的输出结果是()
#include <iostream>
using namespace std;
int main() {
int sum=0;
for(int i=1; i<=20; i++) {
if(i%2==0 && i%3==0) break;
if(i%2==0) continue;
sum+=i;
}
cout << sum << endl;
return 0;
}
{{ select(4) }}
- 100
- 105
- 110
- 9
- 以下数组定义和初始化中,正确的是()
{{ select(5) }}
- int a[2][3]={{1,2},{3,4},{5,6}};
- int b[][3]={1,2,3,4,5};
- int c[2][]={1,2,3,4};
- int d[5]={};
- 执行以下代码后,输出结果是()
#include <iostream>
using namespace std;
int main() {
int a[10]={1,3,5,7,9};
for(int i=0; i<10; i+=2) {
cout << a[i+1] << " ";
}
return 0;
}
{{ select(6) }}
- 1 5 9 0 0
- 3 7 0 0 0
- 1 3 5 7 9
- 3 7 随机值 随机值 随机值
- 以下关于函数参数传递的说法,正确的是()
{{ select(7) }}
- 传值调用时,形参的改变会影响实参
- 传引用调用时,形参和实参共享同一块内存空间
- 数组作为参数传递时,会复制整个数组的内容
- 指针参数传递不属于传地址调用
- 执行以下代码后,输出结果是()
#include <iostream>
using namespace std;
void change(int a[], int n) {
for(int i=0; i<n; i++) {
a[i]*=2;
}
}
int main() {
int arr[5]={1,2,3,4,5};
change(arr,3);
for(int i=0; i<5; i++) {
cout << arr[i] << " ";
}
return 0;
}
{{ select(8) }}
- 2 4 6 4 5
- 2 4 6 8 10
- 1 2 3 4 5
- 编译错误
- 以下递归函数调用f(4)的返回值是()
int f(int n) {
if(n==0) return 0;
if(n==1) return 1;
return f(n-1)+f(n-2)+1;
}
{{ select(9) }}
- 5
- 7
- 8
- 9
- 执行以下代码后,输出结果是()
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char str1[10]="abc";
char str2[]="defgh";
strcpy(str1,str2);
cout << strlen(str1) << " " << sizeof(str1) << endl;
return 0;
}
{{ select(10) }}
- 5 5
- 5 10
- 3 10
- 3 5
- 以下数学库函数中,用于计算绝对值的是()
{{ select(11) }}
- abs()
- floor()
- ceil()
- round()
- 执行以下代码后,输出结果是()
#include <iostream>
#include <cmath>
using namespace std;
int main() {
cout << (int)sqrt(20) << " " << ceil(3.2) << " " << floor(4.9) << endl;
return 0;
}
{{ select(12) }}
- 4 3 4
- 4 4 4
- 5 3 5
- 5 4 5
- 以下问题中,最适合使用模拟法解决的是()
{{ select(13) }}
- 计算n的阶乘
- 找出100以内的所有素数
- 模拟扑克牌洗牌过程
- 求两个数的最大公约数
- 枚举法的时间复杂度主要取决于()
{{ select(14) }}
- 问题的规模
- 枚举的范围和判断条件的复杂度
- 计算机的性能
- 编程语言的类型
- 执行以下代码后,输出结果是()
#include <iostream>
using namespace std;
int main() {
int i=0, j=0;
while(i<5) {
i++;
if(i%2==0) continue;
j++;
}
cout << j << endl;
return 0;
}
{{ select(15) }}
- 2
- 3
- 4
- 5
- 以下关于字符数组和字符串的说法,错误的是()
{{ select(16) }}
- 字符数组可以不包含字符串结束符'\0'
- strcmp("abc","abd")的返回值大于0
- strlen()函数计算的是字符串的实际长度,不包括结束符
- 两个字符串不能直接用==运算符比较是否相等
- 执行以下代码后,输出结果是()
#include <iostream>
using namespace std;
int main() {
int a[4][4]={{1,2,3},{4,5},{6}};
cout << a[2][1] << " " << a[3][3] << endl;
return 0;
}
{{ select(17) }}
- 0 0
- 5 0
- 6 随机值
- 0 随机值
- 以下函数定义中,正确的是()
{{ select(18) }}
- int f(int a, int b=0, int c) {}
- void f(int a) { return a+1; }
- int f() { return; }
- int f(int a, int b) { return a+b; }
- 执行以下代码后,输出结果是()
#include <iostream>
using namespace std;
int f(int n) {
if(n<=2) return n;
return f(n-1)*f(n-2);
}
int main() {
cout << f(5) << endl;
return 0;
}
{{ select(19) }}
- 8
- 12
- 16
- 24
- 以下代码的功能是()
#include <iostream>
using namespace std;
int main() {
int n, rev=0;
cin >> n;
while(n>0) {
rev=rev*10+n%10;
n/=10;
}
cout << rev << endl;
return 0;
}
{{ select(20) }}
- 计算n的各位数字之和
- 判断n是否为回文数
- 将n的各位数字反转
- 计算n的位数
- 执行以下代码后,输出结果是()
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char str[]="programming";
for(int i=0; i<strlen(str); i++) {
if(str[i]=='m') {
str[i]='M';
break;
}
}
cout << str << endl;
return 0;
}
{{ select(21) }}
- prograMMing
- prograMming
- prograMMing
- prograMming
- 以下关于多层循环的说法,正确的是()
{{ select(22) }}
- 多层循环中,内层循环的执行次数等于外层循环的执行次数
- break语句只能跳出当前所在的那一层循环
- continue语句可以跳过外层循环的本次迭代
- 三层循环的时间复杂度一定是O(n³)
- 执行以下代码后,输出结果是()
#include <iostream>
using namespace std;
int main() {
int sum=0;
for(int i=1; i<=4; i++) {
for(int j=i; j<=4; j++) {
for(int k=j; k<=4; k++) {
sum++;
}
}
}
cout << sum << endl;
return 0;
}
{{ select(23) }}
- 10
- 15
- 20
- 25
- 以下变量类型转换中,属于隐式类型转换的是()
{{ select(24) }}
- int a=(int)3.14;
- double b=5;
- char c='a'; int d=(int)c;
- long e=100; short f=(short)e;
- 执行以下代码后,输出结果是()
#include <iostream>
using namespace std;
int main() {
int a=5, b=10, c=15;
if(a>b)
cout << 1;
else if(b>c)
cout << 2;
else if(c>a)
cout << 3;
else
cout << 4;
return 0;
}
{{ select(25) }}
- 1
- 2
- 3
- 4
- 执行以下代码后,输出结果是()
#include <iostream>
using namespace std;
int main() {
int a[5]={2,4,6,8,10};
int *p=a;
cout << *(p+2) << " " << *p+2 << endl;
return 0;
}
{{ select(26) }}
- 6 4
- 6 6
- 8 4
- 8 6
- 执行以下代码后,输出结果是()
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char str1[]="hello";
char str2[]="hello";
if(str1==str2) cout << "equal";
else cout << "not equal";
return 0;
}
{{ select(27) }}
- equal
- not equal
- 编译错误
- 运行时错误
- 执行以下代码后,输出结果是()
#include <iostream>
using namespace std;
int main() {
int sum=0;
for(int i=1; i<=10; i++) {
int j;
for(j=1; j<=i; j++) {
if(i%j==0 && j!=1 && j!=i) break;
}
if(j>i) sum+=i;
}
cout << sum << endl;
return 0;
}
{{ select(28) }}
- 17
- 18
- 28
- 29
二、多选题(共10题,每题3分,共30分)
- 以下关于二维数组的说法,正确的有()
{{ multiselect(29) }}
- 二维数组可以看作是数组的数组
- 二维数组在定义时可以省略第一维的长度
- 二维数组在定义时可以省略第二维的长度
- 二维数组的元素在内存中是连续存储的
- 以下字符串函数的使用中,可能导致数组越界的有()
{{ multiselect(30) }}
- strcpy(str1,str2) 当str2的长度大于等于str1的长度时
- strcat(str1,str2) 当str1剩余空间不足以容纳str2时
- strlen(str) 当str没有以'\0'结束时
- strcmp(str1,str2) 当两个字符串长度不同时
- 以下关于递归的说法,错误的有()
{{ multiselect(31) }}
- 递归函数必须有且只有一个终止条件
- 递归调用的次数越多,程序的运行效率越高
- 所有递归问题都可以用循环来解决
- 递归函数中不能包含循环结构
- 以下关于文件操作的说法,正确的有()
{{ multiselect(32) }}
- 文件操作完成后必须调用close()函数关闭文件
- 可以使用ios::in | ios::out模式同时读写文件
- eof()函数在读取到文件结束符时返回true
- 以ios::app模式打开文件时,写入指针会定位到文件开头
- 以下关于分支结构的说法,错误的有()
{{ multiselect(33) }}
- if语句后面必须跟else语句
- switch语句中case的顺序不影响程序的执行结果
- switch语句中case后面可以跟变量表达式
- 多个if-else语句可以用switch语句来替代
- 以下关于循环结构的说法,正确的有()
{{ multiselect(34) }}
- for循环的三个表达式都可以省略
- while(1)是一个无限循环
- do-while循环的循环体至少执行一次
- 循环嵌套的层数最多不能超过3层
- 以下问题中,适合使用枚举法解决的有()
{{ multiselect(35) }}
- 鸡兔同笼问题
- 找出所有三位数的水仙花数
- 计算斐波那契数列的第n项
- 分解质因数问题
- 以下关于数组的说法,错误的有()
{{ multiselect(36) }}
- 数组的下标可以是负数
- 数组名可以作为左值被赋值
- 数组的大小可以在运行时动态确定
- 数组元素的类型必须相同
- 以下关于函数的说法,正确的有()
{{ multiselect(37) }}
- 函数可以没有参数
- 函数可以没有返回值
- 函数可以重载,即函数名相同但参数列表不同
- 函数可以调用自身,这就是递归
- 以下关于模拟法和枚举法的说法,正确的有()
{{ multiselect(38) }}
- 模拟法是按照问题的实际步骤一步步模拟执行
- 枚举法是列出所有可能的情况并逐一验证
- 模拟法的时间复杂度通常比枚举法低
- 有些问题既可以用模拟法也可以用枚举法解决
三、判断题(共7题,每题2分,共14分)
- 在C++中,double类型的变量可以精确存储所有小数。
{{ select(39) }}
- √
- ×
- 二维数组a[3][4]中,a[1]表示第二行的首地址。
{{ select(40) }}
- √
- ×
- 函数的默认参数必须从右向左依次声明。
{{ select(41) }}
- √
- ×
- 递归函数如果没有终止条件,会导致程序陷入无限递归,最终栈溢出。
{{ select(42) }}
- √
- ×
- sizeof("abc")的结果是3。
{{ select(43) }}
- √
- ×
- 使用ofstream打开文件时,如果文件不存在,会自动创建该文件。
{{ select(44) }}
- √
- ×
- continue语句的作用是结束整个循环的执行。
{{ select(45) }}
- √
- ×
粤公网安备44195502000195号