算法创意实践挑战赛初中组2025初赛真题1
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
- 以下关于变量定义的C++语句中存在编译错误的是哪项?
{{ select(1) }}
long long pi=3.14;int a=27,b[10],c[3][3];int x,y, z=10,11,12;bool f=false;
- 执行下列代码,输入"hello world"(不带引号),输出结果为?
string s;
cin >> s;
cout << s;
{{ select(2) }}
- hello world
- 空字符串
- world
- hello
- C++程序流程控制的基本结构不包括以下哪项?
{{ select(3) }}
- 分支结构
- 循环结构
- 数据结构
- 顺序结构
- 找出以下代码中哪一行是C++中合法的注释?
{{ select(4) }}
//注释此条语句#注释此条语句("注释此条语句")<!--注释此条语句-->
- 在C++中,以下哪条语句可以正确输出“Hello,World!”?
{{ select(5) }}
print("Hello, world!");cout <<"Hello, World!";include("Hello, World!");cin >> "Hello, World!";
- 执行下列C++代码后,计算
s[0].d+s[1].i,结果是多少?
struct S { double d; int i; };
S s[2]={{1.5,1}, {2.5,2}};
{{ select(6) }}
- 4
- 4.5
- 3.5
- 3
- 补全以下代码,将数组a按升序排列。下列选项中哪一项正确?
int a[7]= {7, 1, 4, 2, 2, 3, 6};
int N=7;
for (int i=0; i<N-1; i++) {
for (int j=0; j<①; j++) {
if (a[j] > a[j+1]) swap(a[j], a[j+1]);
}
}
{{ select(7) }}
- N-i-1
- i-1
- i
- N
- 以下说法正确的是?
{{ select(8) }}
- 执行代码
cout<<13.8%2;会输出1.8 - 将一个浮点数赋值给一个char类型的变量会出现运行时错误
- 如果代码中不含有
#include<iostream>将无法通过编译 - C++可以定义无返回值且无参数函数
- 下列C++代码中哪个语句运行结果是7?
{{ select(9) }}
cout << (char)7;cout<<(int(4.3333333+2.6666666));cout<<66/9;cout<<15/2.0;
- 输入一个DNA序列:由字符A、C、G和T组成的字符串。补充下列代码找到最长的连续相同字符子串。下列选项中哪一项正确?
string s;
cin>> s;
int len=①, ans = 1;
for(int i=②; i<s.size(); i++) {
if(s[i]==s[③]) len++;
else len = 1;
if(④) ans=len;
}
cout<< ans;
{{ select(10) }}
- 1,1,i-1,len>ans
- 0,0,i+1,len>ans
- 1,1,i-1, len<ans
- 0,0,i+1, len<ans
- 想要打印等腰三角形,输入n=4时,输出如下:
*
**
* *
* *
* *
**
*
代码空白处应该填入( )。
int n;
cin >> n;
for (int i= 1; i <= n; i++) {
if(i == 1) cout << "*" << endl;
else {
cout << "*";
for (int j= 1; j<=i-2; j++) cout << " ";
cout << "*" << endl;
}
}
for (int i=①; i>= 1; i--) {
if(i== ②) cout << "*" <<endl;
else {
cout << "*";
for (int j=1; j<=i-2; j++) cout << " ";
cout << "*" << endl;
}
}
{{ select(11) }}
- n-1, n-1
- n, n-1
- n, 1
- n-1, 1
- 从一个2x2网格的左上角出发,若只允许向右或向下移动,恰好有如下6条路径可以到达右下角:

补全以下代码,计算对于9x9的网格,有多少条路径可以到达右下角?
int g[10][10]= {};
①;
for (int i=0; i<10; i++) {
for (int j=0; j<10; j++) {
if(i-1>=0) g[i][j] += g[i-1][j];
② g[i][j] += g[i][j-1];
}
}
cout << g[9][9];
{{ select(12) }}
g[0][0]=1,if(j-1>=0)g[1][1]= 1,if(j-1>=0)g[0][0]= 1, else if(j-1>=0)g[1][1] = 1, else if(j-1>=0)
- 有n个人,第i个人的当前头发长度为
L[i]()。每个人的头发每天增长1。请计算并输出从第一天开始,第一次出现头发长度至少为t的人数 是第几天?
int n,t,p;
int L[100], cnt;
cin >> n >> t >> p;
for (int i=0; i<n; i++) cin >> L[i];
for (int i=1; i < t; i++) {
cnt=0;
for (int j=0; j<n; j++) {
if(①) cnt++;
}
if(②) {
cout << i << endl;
break;
}
}
{{ select(13) }}
L[i]+j>=t, cnt>=pL[j]+i>t, cnt>pL[j]+i>=t, cnt>=pL[i]+j>t, cnt>p
- 执行下列程序,输出结果为?
#include <iostream>
using namespace std;
int main() {
int i=1, j=1;
int x = i++, y = ++ j;
cout<<i<<" "<<j<<" "<<x<<" "<<y;
return 0;
}
{{ select(14) }}
- 1 2 2 1
- 2 2 1 2
- 1 2 2 2
- 2 2 2 2
- 补全下列代码,计算n!()的阶乘中后缀0的个数。下列选项中哪一项正确? 例如:5! = 120,它有1个后缀0。20!=2432902008176640000,它有4个后缀0。 提示:每个后缀0都是由一个因子2和一个因子5相乘得到的,而在阶乘中因子2的个数远多于因子5的个数,因此只需统计因子5的个数。一个5的倍数可以提供至少1个因子5;一个25的倍数可以提供至少2个因子5;一个125的倍数可以提供至少3个因子5;以此类推。
int n, i = ① , ans =0;
cin >> n;
while(②) {
i*=5;
ans += ③;
}
cout << ans;
{{ select(15) }}
5,i<=n,i1,i<=n/5,n/i1,i<n/5,n/i5,i<n,i
- C++中,逻辑与
&&的优先级高于逻辑或||,因此true||false&&true等价于true||(false&&true)。
{{ select(16) }}
- 正确
- 错误
- ASCII码表中,所有数字字符('0'到'9')是连续的。
{{ select(17) }}
- 正确
- 错误
max(1,max(2,3))是合法的表达式,返回值为3。
{{ select(18) }}
- 正确
- 错误
- 选择排序的时间复杂度在最好的情况下是O(n)。
{{ select(19) }}
- 正确
- 错误
- 二维数组
int a[2][3],则数组a一共有6个元素。
{{ select(20) }}
- 正确
- 错误