#4641. 信息素养智汇少年挑战赛初赛试卷一(初)
信息素养智汇少年挑战赛初赛试卷一(初)
一、单选题
- 执行以下代码后,输出结果是( )
#include <iostream>
using namespace std;
int main() {
int a=5, b=2;
cout << (double)a/b << endl;
return 0;
}
{{ select(1) }}
- 2
- 2.0
- 2.5
- 编译错误
- 以下关于文件读写的说法,正确的是( )
{{ select(2) }}
- 使用ifstream对象可以向文件写入数据
- 打开文件时必须指定ios::in模式才能读取文件
- 读取文件结束时,eof()函数会返回true
- 文件操作完成后不需要关闭文件,系统会自动处理
- 执行以下代码后,变量x的值是( )
int x=10;
if(x>5)
if(x>8) x=20;
else x=15;
{{ select(3) }}
- 10
- 15
- 20
- 不确定
- 以下代码的输出结果是( )
#include <iostream>
using namespace std;
int main() {
int sum=0;
for(int i=1; i<=10; i++) {
if(i%3==0) continue;
sum+=i;
}
cout << sum << endl;
return 0;
}
{{ select(4) }}
- 55
- 37
- 45
- 18
- 以下数组定义中,正确的是( )
{{ select(5) }}
- int a[5]={1,2,3,4,5,6};
- int b[]={1,2,3};
- int c[3.5];
- int d[0];
- 执行以下代码后,输出结果是( )
#include <iostream>
using namespace std;
int main() {
int a[5]={1,2,3,4,5};
cout << a[5] << endl;
return 0;
}
{{ select(6) }}
- 5
- 0
- 随机值
- 编译错误
- 以下关于函数的说法,错误的是( )
{{ select(7) }}
- 函数可以没有返回值
- 函数可以有多个参数
- 函数可以嵌套定义
- 函数可以递归调用
- 执行以下代码后,输出结果是( )
#include <iostream>
using namespace std;
void swap(int a, int b) {
int temp=a;
a=b;
b=temp;
}
int main() {
int x=3, y=5;
swap(x,y);
cout << x << " " << y << endl;
return 0;
}
{{ select(8) }}
- 3 5
- 5 3
- 3 3
- 5 5
- 以下递归函数的功能是计算( )
int f(int n) {
if(n==0) return 1;
return n*f(n-1);
}
{{ select(9) }}
- n的平方
- n的阶乘
- n的累加和
- 斐波那契数列
- 执行以下代码后,输出结果是( )
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char str1[]="hello";
char str2[]="world";
strcat(str1,str2);
cout << strlen(str1) << endl;
return 0;
}
{{ select(10) }}
- 5
- 10
- 11
- 编译错误
- 以下数学库函数中,用于计算平方根的是( )
{{ select(11) }}
- pow()
- sqrt()
- abs()
- sin()
- 执行以下代码后,输出结果是( )
#include <iostream>
#include <cmath>
using namespace std;
int main() {
cout << pow(2,3) << endl;
return 0;
}
{{ select(12) }}
- 5
- 6
- 8
- 9
- 模拟法适合解决以下哪种问题( )
{{ select(13) }}
- 求最大公约数
- 排序问题
- 模拟时钟走时
- 查找问题
- 枚举法的核心思想是( )
{{ select(14) }}
- 分而治之
- 逐一尝试所有可能的情况
- 递归求解
- 贪心选择
- 执行以下代码后,输出结果是( )
#include <iostream>
using namespace std;
int main() {
int i=0;
while(i<10) {
i++;
if(i==5) break;
}
cout << i << endl;
return 0;
}
{{ select(15) }}
- 4
- 5
- 9
- 10
- 以下关于字符数组的说法,正确的是( )
{{ select(16) }}
- 字符数组只能存储字符串
- 字符串的结束符是'\0'
- 可以用=直接给字符数组赋值
- 字符数组的长度等于字符串的长度
- 执行以下代码后,输出结果是( )
#include <iostream>
using namespace std;
int main() {
int a[3][3]={{1,2},{3,4},{5,6}};
cout << a[1][2] << endl;
return 0;
}
{{ select(17) }}
- 4
- 5
- 6
- 0
- 以下函数调用中,参数传递方式为传引用的是( )
{{ select(18) }}
- void f(int x);
- void f(int *x);
- void f(int &x);
- void f(int x[]);
- 执行以下代码后,输出结果是( )
#include <iostream>
using namespace std;
int f(int n) {
if(n<=1) return 1;
return f(n-1)+f(n-2);
}
int main() {
cout << f(5) << endl;
return 0;
}
{{ select(19) }}
- 5
- 8
- 13
- 21
- 以下代码的功能是( )
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
bool flag=true;
for(int i=2; i*i<=n; i++) {
if(n%i==0) {
flag=false;
break;
}
}
cout << flag << endl;
return 0;
}
{{ select(20) }}
- 判断n是否为偶数
- 判断n是否为质数
- 计算n的平方根
- 计算n的约数个数
三、判断题
- 在C++中,int类型的变量可以存储任意大小的整数。( )
{{ select(36) }}
- √
- ×
- 数组的大小可以是变量。( )
{{ select(37) }}
- √
- ×
- 函数的返回值类型可以是void,表示没有返回值。( )
{{ select(38) }}
- √
- ×
- 递归函数的执行效率比循环高。( )
{{ select(39) }}
- √
- ×
- 字符串"abc"的长度是4。( )
{{ select(40) }}
- √
- ×
- 使用ifstream打开文件时,如果文件不存在,会自动创建该文件。( )
{{ select(41) }}
- √
- ×
- break语句可以跳出所有层循环。( )
{{ select(42) }}
- √
- ×
- 传值调用时,形参和实参是两个不同的变量。( )
{{ select(43) }}
- √
- ×
- 二维数组a[3][4]共有12个元素。( )
{{ select(44) }}
- √
- ×
- 枚举法的时间复杂度通常是O(n)。( )
{{ select(45) }}
- √
- ×
粤公网安备44195502000195号