#YGAP17. 市赛模拟题(三)
市赛模拟题(三)
一选择题:15小题,每小题2分,共30分
1.以下关于寄存器的说法,哪个是错误的?{{ select(1) }}
- 寄存器中的信息在断电后会丢失
- Cache是寄存器的英文名字
- 寄存器是CPU的组成部分
- 寄存器的读写速度比RAM快
2.以下关于内存储器的说法,哪个是错误的?{{ select(2) }}
- CPU可以直接访问内存储器
- ROM是内存储器
- 内存储器也可以称为主存储器
- C盘是内存储器
3.某个U盘的容量是4GB,如果全部用来储存中文,能保存多少个字?{{ select(3) }}
4.以下哪个选项不是硬件?{{ select(4) }}
- 打印机
- 闪存
- 计算机病毒
- 网卡
5.以下关于系统软件的说法,哪个是正确的?{{ select(5) }}
- 系统软件的主要功能是调度,监控和维护计算机系统
- Linux系统是苹果公司的产品
- 计算机语言处理程序不是系统软件
- 应用软件和系统软件可以互相独立运行
6.以下关于C++的说法,哪个是错误的?{{ select(6) }}
- C++是一种解析性语言
- C++是一种编译性语言
- C++是一种高级语言
- C++是一种面向对象语言
7.以下哪个数字最小?{{ select(7) }}
8.计算:{{ select(8) }}
- 1000 0010
- 1010 1101
- 1101 1010
- 1001 0011
9.以下关于编码的说法,哪个是错误的?{{ select(9) }}
- ASCII码和汉字交换码都是内码
- 一个ASCII码占用8比特
- 标准ASCII码能表达128种字符
- UTF-8编码的字符在计算机中以8进制存储
10.计算两个单字节补码的和:{{ select(10) }}
11.单字节补码能表达最大的数是多少?{{ select(11) }}
- 127
- 128
- 255
- 256
12.IPv4的地址长度是32位,IPv6的地址长度是128位。请问IPv6能表示的地址数量是IPv4的多少倍?{{ select(12) }}
13.以下关于网络协议的说法,哪个是错误的{{ select(13) }}
- TCP/IP协议是因特网的基础
- TCP/IP协议是以太网的基础
- FTP协议是TCP/IP协议的一部分
- 一个IP地址可以对应多个域名
14.以下哪个表达式的计算结果是flase?{{ select(14) }}
- $y=2000:y \% 400==0 \ ||\ y \%4==0 \ \&\& \ y \%100 !=0$
- $A=true,B=false,C=true,D=false:(B \vee C \vee D )\vee D \land A$
15.对数组使用某种方法从小到大排序,数组的变化过程如下,请问使用的排序方法是?{{ select(15) }}
- 冒泡
- 选择
- 插入
- 快速
{8,3,2,4,1,5,7}
{3,8,2,4,1,5,7}
{2,3,8,4,1,5,7}
{2,3,4,8,1,5,7}
二程序阅读题,4小题,每道小题包含5道选择题,每道选择题2分,共40分
程序A:
#include<bits/stdc++.h>
using namespace std;
string s;
int k,num;
int main(){
cin>>k;
cin>>s;//第16题
int quan=1;
int ans=0;
for(int i=s.size()-1;i>=0;i--){//第17题
if(s[i]>='0' && s[i]<='9'){//第19题
num=s[i]-'0';
}else if(s[i]>='a' && s[i]<='z'){
num=s[i]-'a'+10;
}
else{
num=0;
}
ans+=num*quan;
quan*=k;
}
cout<<ans;
return 0;
}
16.第7行的代码改写成getline(cin,s),对程序的运行结果没有影响{{ select(16) }}
- 正确
- 错误
17.第11行的代码改写成for(int i=0;i<s.size();i++),对程序的运行结果没有影响{{{ select(17) }}
- 正确
- 错误
18.如果输入到s的字符串只包含数字和小写字母,那么输出的结果一定是正整数?{{ select(18) }}
- 正确
- 错误
19.第12行的代码改写成if('0' <= s[i] <= '9'),对程序的运行结果没有影响{{ select(19) }}
- 正确
- 错误
20.如果输入的数据是16 a1b2,输出的结果是?{{ select(20) }}
- 41349
- 34914
- 41394
- 94313
程序B
#include<bits/stdc++.h>
using namespace std;
int n;
int a[110];
void bubble_sort(){//第21题
for(int i=0;i<n;i++){
bool ok=1;
for(int j=0;j+1<n;j++){//第24题
if(a[j]>a[j+1]){//第22,23题
ok=0;
swap(a[j],a[j+1]);
}
}
if(ok) return;
}
}
int main(){
cin>>n;
for(int i=0;i<n;i++) cin>>a[i];
bubble_sort();
for(int i=0;i<n;i++) cout<<a[i]<<' ';
return 0;
}
21.第5行代码,因为函数没有参数列表,所以可以不写小括号{{ select(21) }}
- 正确
- 错误
22.第9行代码改成if(a[j-1]>a[j])对程序的输出结果没有影响{{ select(22) }}
- 正确
- 错误
23.第9行代码改成if(a[j]>=a[j+1])对程序的输出结果没有影响{{ select(23) }}
- 正确
- 错误
24.第8行代码的循环条件改写成什么对效率的提升最大?{{ select(24) }}
- j+i<n-1
- j+i<=n-1
- j+i<n+1
- j+i<=n+1
25.该算法的平均时间复杂的是多少?{{ select(25) }}
程序C
#include<bits/stdc++.h>
using namespace std;
int main(){
int a[100]={};//第26题
int n;cin>>n;
for(int i=0;i<n;i++) //第27题
cin>>a[i];
int* big=a;//第28题
int* small=a;
for(int i=1;i<n;i++){
if(a[i]>*big) big=&a[i];//第29题
if(a[i]<*small) small=&a[i];
}
cout<<abs(big-small);
return 0;
}
26.第4行代码,如果定义数组a的时候不进行初始化,对程序输出结果没有影响{{ select(26) }}
- 正确
- 错误
27.如果把第6行代码改成for(int i=1;i<=n;i++),对程序输出结果没有影响{{ select(27) }}
- 正确
- 错误
28.第9行代码可以改写成{{ select(28) }}
- int* big=0;
- int& big=0;
- int* big=&a[0];
- int big=a[0];
29.第12行代码可以改写成{{ select(29) }}
- if(a[i]>*big) big=a+i;
- if(a[i]>*big) big=a-i;
- if(a[i]>*big) big=a*i;
- if(a[i]>*big) big=a&i;
30.输入8 3 8 5 2 1 4 7 6,输出{{ select(30) }}
- 3
- 7
- -3
- -7
程序D
#include<bits/stdc++.h>
using namespace std;
int yanghui[10][10];
int func1(int x,int y){
if(y==0) return 1;//第31题
if(y==x) return 1;//第31题
return func1(x-1,y-1)+func1(x-1,y);
}
int func2(int x,int y){
for(int i=0;i<=x;i++){
yanghui[i][0]=1;
for(int j=1;j<=i;j++){
yanghui[i][j]=yanghui[i-1][j-1]+yanghui[i-1][j];
}
}
return yanghui[x][y];
}
int main(){
int a,b;
cin>>a>>b;
cout<<func1(a,b)<<endl;
cout<<func2(a,b)<<endl;
return 0;
}
31.交换第5,第6行代码,对输出结果没有影响{{ select(31) }}
- 正确
- 错误
32.对于func1来说,如果传入的参数x小于参数y,程序会发生错误{{ select(32) }}
- 正确
- 错误
33.估算func2的时间复杂度{{ select(33) }}
34.输入5 3,func1的返回值是{{ select(34) }}
- 4
- 5
- 10
- 20
35.输入6 2,func2的返回值是{{ select(35) }}
- 5
- 6
- 10
- 15
三完善程序题,3小题,每道小题包含5道选择题,每道选择题2分,共30分
程序A:
输入两个格式形如yyyy mm dd的日期,计算这两个日期相差了多少天
2023 6 5
2023 6 3
2
2023 5 30
2023 6 3
4
#include<bits/stdc++.h>
using namespace std;
struct data{
int y,m,d;
};
bool cmp(data a,data b){
if(a.y!=b.y) return a.y>b.y;
if(a.m!=b.m) return a.m>b.m;
return 第36题;
}
int day_of_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int main(){
data a,b;
cin>>a.y>>a.m>>a.d;
cin>>b.y>>b.m>>b.d;
if(第37题) swap(a,b);
int ans=0;
if(a.y%4==0 && a.y%100!=0 || a.y%400==0 ) 第38题;
while(1){
if(第39题) break;
ans++;
a.d++;
if(第40题){
a.d=1;
a.m++;
if(a.m>12){
a.m=1;
a.y++;
if(a.y%4==0 && a.y%100!=0 || a.y%400==0 ) day_of_month[2]=29;
else day_of_month[2]=28;
}
}
}
cout<<ans;
return 0;
}
36处该填{{ select(36) }}
- true
- false
- a.d>b.d
- a.d<b.d
37处该填{{ select(37) }}
- a>b
- a<b
- cmp(a,b)
- !cmp(a,b)
38处该填{{ select(38) }}
- day_of_month[1]=28
- day_of_month[1]=29
- day_of_month[2]=28
- day_of_month[2]=29
39处该填{{ select(39) }}
a.y!=b.y && a.m!=b.m && a.d!=b.da.y!=b.y || a.m!=b.m || a.d!=b.da.y==b.y && a.m==b.m && a.d==b.da.y==b.y || a.m==b.m || a.d==b.d
40处该填{{ select(40) }}
- a.d==day_of_month[a.m]
- a.d>day_of_month[a.m]
- a.d==day_of_month[b.m]
- a.d>day_of_month[b.m]
程序B: 有一个长度为n的int数组,从中截取一个子段,要求子段和不超过k,求能截取子段的最大长度(使用尺取法)
10 4
2 1 3 1 1 2 2 1 1 4
3
10 8
2 1 3 1 1 2 2 1 1 4
6
#include<bits/stdc++.h>
using namespace std;
int a[1234567];
int sum,ans;
int main(){
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>a[i];
}
第41题;
while(第42题){
if(第43题){
ans=max(ans,第44题);
R++;
sum+=a[R];
}else{
sum-=a[L];
第45题;
}
}
cout<<ans;
return 0;
}
41处该填{{ select(41) }}
- int L=0,R=0
- int L=0,R=1
- int L=1,R=0
- int L=1,R=1
42处该填{{ select(42) }}
- L<n
- L<=n
- R<n
- R<=n
43处该填{{ select(43) }}
- sum<k
- sum<=k
- sum>k
- sum>=k
44处该填{{ select(44) }}
- sum
- R-L
- R-L+1
- R-L-1
45处该填{{ select(45) }}
- L++
- L--
- R++
- R--
程序C: 从一个int数组中截取子段,要求截出来的子段和是7的倍数,截取出来的子段的最大长度是多少?
#include<bits/stdc++.h>
using namespace std;
int a[100000],L[7],R[7];
int main(){
int ans=0;
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
第46题;
}
for(int i=1;i<=n;i++) 第47题;
for(int i=0;i<7;i++){
for(int j=0;j<=n;j++){
if(a[j]==i){
第48题;
break;
}
}
}
for(int i=0;i<7;i++){
for(int j=n;j>=0;j--){
if(a[j]==i){
第49题;
break;
}
}
}
for(第50题){
ans=max(ans,R[i]-L[i]);
}
cout<<ans;
return 0;
}
46处该填{{ select(46) }}
- a[i]%=7
- a[i]/=7
- a[i]+=a[i-1]
- a[i]-=a[i-1]
47处该填{{ select(47) }}
- a[i]%=7
- a[i]/=7
- a[i]+=a[i-1]
- a[i]-=a[i-1]
48处该填{{ select(48) }}
- L[i]=j
- L[j]=i
- R[i]=j
- R[j]=i
49处该填{{ select(49) }}
- L[i]=j
- L[j]=i
- R[i]=j
- R[j]=i
50处该填{{ select(50) }}
- int i=1;i<=n;i++
- int i=n;i>=1;i--
- int i=0;i<7;i++
- int i=0;i<6;i++
程序D: 数轴上有n条线段,其中第i条线段的左端点和右端点是和,如果两条线段有重合的部分,那么就可以融合成一条线段.求这n条线段融合后最长的线段的长度
4
1 3
3 5
8 10
9 18
10
#include<bits/stdc++.h>
using namespace std;
struct line{
int L,R;
}a[1024];
bool cmp(line x,line y){
第51题;
}
int main(){
int n;cin>>n;
for(int i=0;i<n;i++){
cin>>a[i].L>>a[i].R;
}
第52题;
int ans=0;
int l=a[0].L;
int r=a[0].R;
for(第53题){
if(第54题) l=a[i].L;
r=a[i].R;
ans=max(ans,第55题);
}
cout<<ans;
return 0;
}
51处该填{{ select(51) }}
- return x.L>y.L
- return x.R>y.R
- return x.L<y.L
- return x.R<y.R
52处该填{{ select(52) }}
- sort(a,a+n,cmp)
- sort(a+1,a+1+n,cmp)
- sort(cmp,a,a+n)
- sort(cmp,a+1,a+1+n)
53处该填{{ select(53) }}
- int i=1;i<n;i++
- int i=1;i<=n;i++
- int i=n;i>=1;i--
- int i=n-1;i>=1;i--
54处该填{{ select(54) }}
- a[i].L>l
- a[i].L<l
- a[i].L>r
- a[i].L<r
55处该填{{ select(55) }}
- r-l
- a[i-1].R-l
- r-a[i].L
- a[i].R-a[i].L
程序E(垂直柱状图)
输入4个字符串,统计每种字母的出现次数,以柱状图的形式输出
THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.
THIS IS AN EXAMPLE TO TEST FOR YOUR
HISTOGRAM PROGRAM.
HELLO!
*
*
* *
* * * *
* * * *
* * * * * *
* * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * *
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
#include<bits/stdc++.h>
using namespace std;
int cnt[1000];
int main(){
string s;
for(int j=0;j<4;j++){
第56题;
for(int i=0;i<s.size();i++){
第57题;
}
}
int big=0;
for(int i='A';i<='Z';i++){
big=max(big,第58题);
}
for(第59题){
for(int j='A';j<='Z';j++){
if(cnt[j]>=i) cout<<"* ";
else cout<<" ";
}
cout<<endl;
}
for(第60题){
cout<<i<<' ';
}
return 0;
}
56处该填{{ select(56) }}
- cin>>s
- getline(cin,s)
- getline(cin>>s)
- scanf("%s",&s)
57处该填{{ select(57) }}
- cnt[i]++
- s[i]++
- cnt[s[i]]++
- cnt[i]=s[i]
58处该填{{ select(58) }}
- i
- cnt[i]
- s[i]
- cnt[s[i]]
59处该填{{ select(59) }}
- int i=0;i<s.size();i++
- int i=s.size()-1;i>=0;i--
- int i=1;i<=big;i++
- int i=big;i>=1;i--
60处该填{{ select(60) }}
- int i='A';i<='Z';i++
- char i='A';i<='Z';i++
- int i=1;i<=big;i++
- int i=cnt['A'];i<=cnt['Z'];i++
程序F: 有一个长度为n的int数组.求它的平均数,中位数,和众数
众数是指一组数据中出现次数最多的数字.如果众数的个数不止一个,输出最小的那一个
中位数是指一组数据经过排序之后,位置排在最中间的数字.如果数据的个数是偶数,那么中位数是中间的两个数字的平均值
8
2 3 1 3 5 2 3 2
2.625
2.5
2
#include<bits/stdc++.h>
using namespace std;
int a[110];
int main(){
int n;cin>>n;
double sum=0.0;
for(int i=1;i<=n;i++){
cin>>a[i];
第61题;
}
sort(a+1,a+1+n);
cout<<sum/n<<endl;
if(n%2==1) cout<<a[(n+1)/2]<<endl;
else cout<<(第62题)<<endl;
int cnt=1,max_cnt=0,max_val;
for(int i=1;i<=n;i++){
if(a[i]==a[i+1]) cnt++;
else 第63题;
if(第64题){
max_cnt=cnt;
max_val=a[i];
}
}
cout<<第65题;
return 0;
}
61处该填{{ select(61) }}
- sum+=a[i]
- a[i]+=a[i-1]
- sum=max(sum,a[i])
- a[i]=max(a[i],a[i-1])
62处该填{{ select(62) }}
- (a[n/2]+a[n/2-1])/2.0
- (a[n/2]+a[n/2+1])/2.0
- (a[n/2]+a[(n+1)/2])/2.0
- (a[n/2]+a[(n-1)/2])/2.0
63处该填{{ select(63) }}
- cnt=0
- cnt=1
- cnt=i
- cnt--
64处该填{{ select(64) }}
- cnt>max_cnt
- a[i]>max_cnt
- a[i]>max)val
- a[i]>cnt
65处该填{{ select(65) }}
- cnt
- max_cnt
- max_val
- sum
