#XXSY2025HDJ. 2025C++华东算法创意初中组J
2025C++华东算法创意初中组J
2025华东算法创意C++初中组
一、单选题(共15题)
1.C++ 程序流程控制的基本结构不包括以下哪项?{{ select(1) }}
- 分支结构
- 数据结构
- 循环结构
- 顺序结构
2.以下哪段代码能将数组**int a[4] = {2, 4, 6, 8};**的所有元素变为原来的⼆倍?{{ select(2) }}
- for (int i=0; i< 4; i++) a[i] +=2;
- for (int i=0; i<4; i++) a[i] *=2;
- for (int i=1; i<=4; i++) a[i] =a[i] *a[i];
- for (int i=1; i<=4; i++) a[i] *=2;
3.以下哪项是分支结构的正确写法?()
{{ select(3) }}
- 'while (n > 0) cout <<"Positive";'
- 'if (x> 0) { cout << "Positive"; else cout <<"Not"; }'
- 'for (int i=0; i< n; i++) cout <<"Positive";'
- 'if (x > 0) cout << "Positive";'
4.执行以下代码,输出的结果是?
int a=14/3*3;
cout << a;
{{ select(4) }}
- 14
- 3
- 0
- 12
5.找出以下代码中哪⼀⾏是 C++ 中合法的注释? {{ select(5) }}
- (*注释此条语句*)
- //注释此条语句
- #注释此条语句
- <!--注释此条语句-->
6.以下说法正确的是?
{{ select(6) }}
- 执行代码cout <<13.8 % 2;会输出 1.8
- 如果代码中不含有#include<iostream>将无法通过编译
- 将一个浮点数赋值给一个 char 类型的变量会出现运行时错误
- C++ 可以定义无返回值且无参数函数
7.执行下列 C++ 代码后,计算s[0].d + s[1].i的结果是多少?
struct S {
double d;
int i;
};
S s[2]={{1.5, 1},{2.5, 2}};
{{ select(7) }}
- 3.5
- 4.5
- 3
- 4
8.输入一个 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(8) }}
- 1, 1, i-1, len <ans
- 0, 0, i+1, len > ans
- 0, 0, i+1, len <ans
- 1, 1, i-1, len> ans
9.输入 6 7,输出的结果是?
int a, b;
cin >> a >> b;
if(a%2==0) a/=2;
if(a%2!=0) a=a*3+1;
cout<< a + b;
{{ select(9) }}
- 28
- 17
- 10
- 13
10.下列 C++ 代码中哪个语句运行结果是 7?
{{ select(10) }}
- cout << (char)7;
- cout <<15/2.0;
- cout <<66 /9;
- cout <<int(4.3333333 +2.6666666);
11.给定⼀个包含n个整数的数组,你的目标是通过最少的操作使数组变为非递减的(即每个元素不小于它前面的元素)。每次操作可以选择任意⼀个元素,并将其值增加1。请补全以下代码,计算需要的最少操作次数。下列选项中哪⼀项正确?
#include<iostream>
using namespace std;
int a[1000];
int main(){
int n, cnt=0;
cin >>n;
for(int i=0; i<n; i++) cin>>a[i];
for(int i=1; i<n; i++){
if(a[i-1]>a[i]){
cnt += _①_;
_②_;// 此处有代码修改a[i]的值
}
}
cout << cnt;
return 0;
}
{{ select(11) }}
- a[i-1]-a[i], a[i] += a[i-1]
- a[i-1] -a[i], a[i] =a[i-1]
- a[i]-a[i-1], a[i-1] -=a[i]
- a[i]-a[i -1], a[i -1] =a[i]
12.执行下列 C++ 代码偏段后输出的是?
long long sum=0;
for(int i=1; i<=6; i++){
long long mul=1;
for(int j=1; j<=i; j++) mul *=i;
sum += mul;
}
cout << sum %10;
{{ select(12) }}
- 8
- 6
- 7
- 9
13.有n个人,第i个人的当前头发长度为(1 <=i<=N)。每个人的头发每天增长1。请计算并输出从第一天开始,第一次出现头发长度至少为t的人数>=p是第几天?
int n, t, p, L[100], cnt;
cin>>n>>t>>p;
int L[100], cnt;
for (inti= 0;i<n; i++) cin >> L[i];
for(int i=1;i<t;i++){// 最多循环t-1次一定得出结论
cnt=0;
for(int j=0; j<n; j++){
if(__①_) cnt++;
}
if(_②_){
cout<<i<< endl;
break;
}
}
{{ select(13) }}
- L[j]+i> t, cnt>p
- L[i] +j>t, cnt>p
- L[i] +j>=t, cnt>=p
- L[j] +i>=t, cnt>=p
14.从一个2x2网格的左上角出发,若只允许向右或向下移动,恰好有如下6条路径可以到达右下角:
补全以下代码,计算对于9x9的网格,有多少条路径可以到达右下角?
int g[10][10]={0};
_①_;
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(14) }}
- g[1][1]=1, if (j-1>=0)
- g(1][1])=1, else if (j-1>=0)
- g[0][0]=1, if(j-1>=0)
- g[0][0] =1, else if (j-1>=0)
15.给定一个由正整数组成的长度为N的序列,(A1,A2,...,),请判断这个序列是否为等比数列。等比数列的定义是: 对于所有1<=i<=N-1,的值都相等,补全以下代码,判断序列A是否为等比数列。下列选项中哪一项正确?
int n;
long long a[100];
bool flag =true;
cin >>n;
for(int i=0; i< n; i++) cin >> a[i];
for(int i=0; i<n-2; i++){
if(_①_) flag =false;
}
if(flag) cout <<"Yes"<< endl;
else cout <<"No"<< endl;
{{ select(15) }}
- a[i] *a[i+1] !=a[i+1] *a[i+2]
- a[i]+a[i+2] !=2 * a[i+1]
- a[i+1] /a[i-1]=a[i-1] /a[i+1]
- a[i] *a[i + 2] !=a[i+1] * a[i+1]
二、判断题(共5题)
1.C++ 中,逻辑与**&&的优先级高于逻辑或||,因此true || false && true等价于true || (false && true)**。{{ select(16) }}
- 正确
- 错误
2.ASCII 码表中,所有数字字符('0' 到 '9')是连续的。{{ select(17) }}
- 正确
- 错误
3.’string s="bcd" ; s[0] = 'a';‘可以正确将 s 的第⼀个字符赋值为 'a'。{{ select(18) }}
- 正确
- 错误
4.结构体struct中只能包含成员变量和成员函数,不能包含结构体类型的变量。{{ select(19) }}
- 正确
- 错误
5.定义**int a[3][3] ={1, 2, 3, 4, 5, 6, 7, 8, 9};后,执行swap(a[1][2], a[2][2]);可以正常运行,并且执行cout << a[2][2];**时,程序会输出 6。
{{ select(20) }}
- 正确
- 错误