C++_4rd_第5期
1、⼩杨正在爬楼梯,需要爬 阶才能到达楼顶。如果每次可以爬 个或 个台阶,下⾯代码采⽤递推算法来计算 ⼀共有多少种不同的⽅法可以爬到楼顶,则横线上应填写( )。 1 int f(int n) { 2 if (n == 1 || n == 2) 3 return n; 4 5 int f1 = 1; 6 int f2 = 2; 7 int res = 0; 8 for (int i = 3; i <= n; i++) { 9 ________________________________ // 在此处填入代码 10 } 11 return res; 12 }()
A、1 res += f1 + f2; 2 f1 = f2; 3 f2 = res;
B、1 res = f1 + f2; 2 f1 = f2; 3 f2 = res;
C、1 res += f1 + f2; 2 f2 = res; 3 f1 = f2;
D、1 res = f1 + f2; 2 f2 = res; 3 f1 = f2;
2、下⾯的描述中,( )不能正确定义⼀个名为Student的结构体以及⼀个包含20个元素的结构数组。()
A、1 struct Student { 2 string name; 3 int age; 4 float score; 5 }; 6 struct Student students[20];
B、1 struct Student { 2 string name; 3 int age; 4 float score; 5 }; 6 Student students[20];
C、1 struct Student { 2 string name; 3 int age; 4 float score; 5 }; 6 Student* students = new Student[20];
D、1 struct Student { 2 string name; 3 int age; 4 float score; 5 }; 6 Student students = new Student[20];
3、给定如下代码,其时间复杂度为( )。 1 int cellRecur(int n) { 2 if (n == 1) 3 return 1; 4 return cellRecur(n - 1) + cellRecur(n - 1) + 1; 5 }()
A、
B、
C、
D、
4、关于插⼊排序的时间复杂度,下列说法正确的是( )。()
A、最好情况和最坏情况的时间复杂度都是
B、最好情况是 ,最坏情况是
C、最好情况是 ,最坏情况是
D、最好情况是 ,最坏情况是
5、关于⼏种排序算法的说法,下⾯说法错误的是( )。()
A、选择排序不是⼀个稳定的排序算法
B、冒泡排序算法不是⼀种稳定的排序算法
C、`插⼊排序是⼀种稳定的排序算法
D、如果排序前2个相等的数在序列中的前后位置顺序和排序后它们2个的前后位置顺序相同,则称为⼀种稳定的 排序算法
6、下⾯程序运⾏的结果是( )。 1 void increaseA(int x) { 2 x++; 3 } 4 void increaseB(int* p) { 5 (*p)++; 6 } 7 int main() { 8 int a = 5; 9 increaseA(a); 10 cout << a << " "; 11 increaseB(&a); 12 cout << a; 13 }()
A、6 7
B、6 6
C、5 6
D、5 5
7、下⾯C++代码执⾏后,输出的是( )。()
A、chen
B、c
C、chen a dai
D、dai
8、下列函数实现排⾏榜中单个元素的位置调整(类似插⼊排序的相邻搬移)。当某玩家分数增加,需将其向 前移动时,while 循环的条件应为( )。 1 struct Player{ int score; }; 2 void up(Player players[], int n, int idx){ 3 Player cur = players[idx]; 4 int i = idx; 5 while( ____________________ ){ 6 players[i] = players[i-1]; 7 i--; 8 } 9 players[i] = cur; 10 }()
A、i > 0 && cur.score > players[i-1].score
B、i > 0 && cur.score < players[i-1].score
C、i < n-1 && cur.score > players[i+1].score 第 5 页 / 共 11 页
D、i < n-1 && cur.score < players[i+1].score
9、在C++中,int arr[3][4] 和 int* arr = new int[12]均可模拟⼀个 ⾏ 列的⼆维数组。关于这两种⽅ 式,下⾯说法错误的是( )。()
A、int arr[3][4]在栈上分配空间,适合数组较⼩的情况;
B、int* arr = new int[12]在堆上分配空间,数组较⼤时也适⽤;
C、这两种⽅式申请的内存空间都是连续的。
D、这两种⽅式申请的内存都能⾃动释放。
10、下⾯关于排序稳定性的描述,正确的是( )。()
A、稳定性指算法的时间复杂度恒定
B、稳定排序保证相同元素的相对顺序不变
C、选择排序是稳定排序
D、插⼊排序不是稳定排序
11、中国计算机学会()在2024年1⽉27⽇的颁奖典礼上颁布了王选奖,王选先⽣的重⼤贡献是( )。(C)
A、制造⾃动驾驶汽车
B、创⽴培训学校
C、发明汉字激光照排系统
D、成⽴⽅正公司
12、C++语⾔中下⾯哪个关键字能够限定对象的作⽤域( )。()
A、extern
B、static
C、inline
D、public
13、下⾯哪种⽅式不能实现将字符串"Happy Spring!"输出重定向到⽂件log.txt( )。()
A、1 freopen("log.txt", "w", stdout); 2 cout << "Happy Spring!" << endl; 3 fclose(stdout);
B、1 std::ofstream outFile("log.txt"); 2 outFile << "Happy Spring!" << endl; 3 outFile.close();
C、1 std::ofstream outFile("log.txt"); 2 cout << "Happy Spring!" << endl; 3 outFile.close();
D、1 ofstream log_file("log.txt"); 2 streambuf* org_cout = cout.rdbuf(); 3 cout.rdbuf(log_file.rdbuf()); 4 cout << "Happy Spring!" << endl; 5 cout.rdbuf(org_cout);
14、下⾯的程序中,如果输⼊10 0,会输出( )。()
A、Division by zero condition!
B、0
C、10
D、100
15、关于直接插⼊排序,下列说法错误的是()()
A、插⼊排序的最好情况是数组已经有序,此时只需要进⾏ 次⽐较,时间复杂度为
B、最坏情况是数组逆序排序,此时需要进⾏ 次⽐较以及 次赋值操作(插⼊)
C、平均来说插⼊排序算法的复杂度为
D、空间复杂度上,直接插⼊法是就地排序,空间复杂度为
关闭
更多问卷
复制此问卷