#YGAP15. 市赛模拟题(一)

市赛模拟题(一)

遇到难题不要害怕,不要摆烂,后面的题目可能比前面的题目简单.认真严肃考试.老师要知道你们的真实水平.

一选择题:15小题,每小题2分,共30分

1.以下哪个选项不是CPU的性能参数?{{ select(1) }}

  • 频率
  • 字长
  • 转速
  • 制程

2.以下哪个存储设备的读写速度最快?{{ select(2) }}

  • RAM
  • Cache
  • M2固态硬盘
  • 蓝光光盘

3.以下哪关于操作系统的说法是错误的?{{ select(3) }}

  • 可以用C++语言编写操作系统
  • 操作系统是计算机的软硬件资源管理器
  • 使用盗版的操作系统是非法行为,所有的操作系统都受到版权保护
  • windows10,IOS,DOS,Linux,unix都是操作系统

4.以下哪关于ip地址的说法是错误的?{{ select(4) }}

  • ip地址是TCP/IP协议的其中一部分内容
  • 保存一个ipv4地址需要4字节
  • 处于两个不同子网的两台计算机可以有一样的ip地址
  • ip地址是计算机在出厂前设定好的

5.某个数码相机拍摄的照片是2490*1680像素的32位真彩色照片。请问2GB的U盘最多能保存这样的照片多少张?{{ select(5) }}

  • 128
  • 177
  • 36
  • 889

6.以下哪个数字最大?{{ select(6) }}

  • (3827)10(3827)_{10}
  • (F2A)16(F2A)_{16}
  • (111111110000)2(1111 1111 0000)_{2}
  • (7654)8(7654)_{8}

7.以下哪个1字节补码最小?{{ select(7) }}

  • 010100000101 0000
  • 111100111111 0011
  • 001111110011 1111
  • 100000101000 0010

8.操作鼠标时,鼠标的位置信息存储在哪里?{{ select(8) }}

  • ROM
  • RAM
  • 控制总线
  • 输入总线

9.以下哪种排序算法在运行的过程中会产生新的逆序对?{{ select(9) }}

  • 冒泡
  • 选择
  • 插入
  • 归并

10.已知字符'A'的ASCII码是65,请问字符'Q'使用扩展ASCII码保存在计算机内部的形式是?{{ select(10) }}

  • 01010001
  • 11010001
  • 00101110
  • 10101111

11.阅读以下代码

long long a[100];
cout<<a<<endl;//输出结果为0x1011 0111
cout<<(a+50);//求这里的输出结果

{{ select(11) }}

  • 0x0010 0100 0111
  • 0x1110 1001
  • 0x1011 0143
  • 0x1011 02a1

12.以下哪段代码能将浮点变量a四舍五入到小数点后两位?{{ select(12) }}

  • a=int(a+0.5)*100/100.0;
  • a=int(a*100)/100.0+0.5;
  • a=int(a*100+0.5)/100.0;
  • a=int((a+0.5)*100)/100.0;

13.该算法流程图的时间复杂度是多少?{{ select(13) }}

  • O(n)O(n)
  • O(n2)O(n^2)
  • O(2n)O(2^n)
  • O(nlogn)O(n \log n)

14.该函数的时间复杂度是多少?

int pow(int x,int a){
	if(a==0) return 1;
	int temp=pow(x,a/2);
	if(a%2==0) return temp*temp;
	else return x*temp*temp;
}

{{ select(14) }}

  • O(loga)O(\log a)
  • O(logx)O(\log x)
  • O(a+x)O(a+x)
  • O(xloga)O(x \log a)

15.以下哪段代码会报错?{{ select(15) }}

  • #define pi 3.14
  • const int pi=3.14;
  • int const pi=3.14;
  • int *pi=3.14;

二程序阅读题,4小题,每道小题包含5道选择题,每道选择题2分,共40分

程序A:

int funcA(int x,int y){
	if(x%y==0) return y;
	return funcA(y,x%y);
}

int funcB(int x,int y){
	if(x==y) return x;
	if(x<y) swap(x,y);
	return funcB(y,x-y);
}

16.如果传入funcA的参数与传入funcB的参数一样,那么funcA与funcB的返回值也一样?{{ select(16) }}

  • 正确
  • 错误

17.如果传入funcA的参数与传入funcB的参数都是(3,0),那么funcA与funcB的报错类型也一样?{{ select(17) }}

  • 正确
  • 错误

18.如果传入funcA的参数是(24,15),那么funcA的返回值是?{{ select(18) }}

  • 1
  • 3
  • 5
  • 8

19.如果传入funcB的参数是(16,15),那么funcB的返回值是?{{ select(19) }}

  • 1
  • 3
  • 5
  • 8

20.以下哪段代码可以代替swap(x,y)?{{ select(20) }}

  • x=x+y;y=x-y;x=x-y
  • int temp=x;y=x;x=temp;
  • int temp=y;x=y;y=x;
  • y=x-y;x=y+x;y=y+x;

程序B

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	if(n<0) cout<<"-";
	int a[110]={};//21题
	int len=0;
	while(n){//22题
		int temp=n%k;
		a[len++]=temp;
		n/=k;
	}
	for(int i=len-1;i>=0;i--){
		if(abs(a[i])<10) cout<<abs(a[i]);
		else cout<<char(abs(a[i])-10+'A');
	}
	return 0;
}

21.第7行代码,定义数组a的时候不进行初始化,对输出结果没有影响{{ select(21) }}

  • 正确
  • 错误

22.第9行代码改成while(n>0)对程序的输出结果没有影响{{ select(22) }}

  • 正确
  • 错误

23.在该程序正常运行过程中变量len可能的最大值是{{ select(23) }}

  • 31
  • 32
  • 109
  • 110

24.输入-6 2,输出结果是?{{ select(24) }}

  • -1-10
  • -110
  • 1110
  • 1010

25.输入2780 16,输出结果是?{{ select(25) }}

  • AAC
  • ABC
  • ACC
  • ADC

程序C

#include<bits/stdc++.h>
using namespace std;
struct node{
	int val;
	int id;
}a[110];
int main(){
	int n;cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].val;
		a[i].id=i;
	}
	for(int i=1;i<n;i++){
		int min_id=i;
		for(int j=i+1;j<=n;j++){//第26题
			if(a[j].val<a[min_id].val){//第27题
				min_id=j;
			}
		}
		swap(a[i],a[min_id]);
	}
	for(int i=1;i<=n;i++){
		cout<<a[i].id;
	}
	return 0;
}

26.第15行代码,如果j的初始值设为i,对程序输出结果没有影响{{ select(26) }}

  • 正确
  • 错误

27.把第16行代码改成if(a[j].val<=a[min_id].val),对程序输出结果没有影响{{ select(27) }}

  • 正确
  • 错误

28.该算法在最好情况下的时间复杂度是多少{{ select(28) }}

  • O(n)O(n)
  • O(nlogn)O(n \log n)
  • O(n2)O(n^2)
  • O(nn)O(n \sqrt n)

29.输入5 9 8 7 6 5,输出{{ select(29) }}

  • 12345
  • 54321
  • 56789
  • 98765

30.输入8 3 3 1 3 3 2 3 3,输出{{ select(30) }}

  • 12333333
  • 33333321
  • 36145278
  • 36124578

程序D

#include<bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin>>s;
	int ans=0,num=0;
	int len=s.size();
	char op='+';//第31题
	for(int i=0;i<len;i++){
		if(s[i]>='0' && s[i]<='9'){
			num=num*10+(s[i]-'0');//第32题
		}else{
			switch (op) {
				case '+':
					ans+=num;
					break;
				case '-':
					ans-=num;
					break;
				case '*':
					ans*=num;
					break;
				case '/'://第33题
					ans/=num;
					break;
			}
			op=s[i];
			num=0;
		}
	}
	cout<<ans;
	return 0;
}

31.如果输入数据是3+7-6=,第8行代码的字符变量op可以不进行初始化赋值,对输出结果没有影响{{ select(31) }}

  • 正确
  • 错误

32.如果输入数据是3+7-6=,第11行代码改写成num=num*10+int(s[i]),对输出结果没有影响{{ select(32) }}

  • 正确
  • 错误

33.如果输入数据是15/3*2+1-4=,第23行代码改写成dafault:,对输出结果没有影响{{ select(33) }}

  • 正确
  • 错误

34.输入12-2*5/2=,输出{{ select(34) }}

  • 1
  • 2
  • 7
  • 25

35.输入(3+5)*(6-4)=,输出{{ select(35) }}

  • -4
  • 44
  • 16
  • 报错

三完善程序题,3小题,每道小题包含5道选择题,每道选择题2分,共30分

程序A: 输入一个整数n,输出一个尺寸为n*n的螺旋矩阵

3
1 2 3
8 9 4
7 6 5
4
1  2  3  4
12 13 14 5
11 16 15 6
10 9  8  7
#include<bits/stdc++.h>
using namespace std;
int n;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
bool vis[10][10];
int a[10][10];
bool in_bound(int x,int y){
	return x>=0 && x<n && y>=0 && y<n;
}
int main() {
	cin>>n;
	int dir=0;
	int cnt=1;
	int x=0;
	int y=0;
	while(第36题){
                int tx,ty;
		a[x][y]=cnt++;
		第37题;
		while(true){
			tx=x+dx[dir];
			ty=y+dy[dir];
			if(in_bound(第38题) && !vis[tx][ty]) break;
			dir=第39题;
		}
		x=tx;
		y=ty;
	}
	a[x][y]=第40题;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			printf("d ",a[i][j]);
		}
		cout<<endl;
	}
	return 0;
}

36处该填{{ select(36) }}

  • true
  • cnt<n*n
  • cnt<=n*n
  • cnt<=n

37处该填{{ select(37) }}

  • vis[x][y]=1
  • vis[tx][ty]=1
  • vis[dx[dir]][dy[dir]]=1
  • vis[tx][ty]=vis[x][y]

38处该填{{ select(38) }}

  • x,y
  • tx,ty
  • dx[x],dy[y]
  • dx[tx],dy[ty]

39处该填{{ select(39) }}

  • dir+1
  • dir%4+1
  • (dir+1)%4
  • -dir

40处该填{{ select(40) }}

  • n
  • cnt
  • cnt+1
  • cnt-1

程序B: 输入一个n*n的矩阵,有k次询问,每次询问给出两个坐标,代表一个子矩阵的左上角和右下角,求该子矩阵中所有元素的和

4 3
1 2 3 4 
5 6 7 8
9 10 11 12
13 14 15 16
1 1 4 4
2 2 3 3
1 2 3 4
136
34
63
#include<bits/stdc++.h>
using namespace std;
int a[100][100];
int main() {
	int n;cin>>n;
	int k;cin>>k;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>a[i][j];
			a[i][j]+=第41题;
		}
	}
	for(第42题){
		for(第43题){
			a[i][j]+=a[i-1][j];
		}
	}
	while(k--){
		int L,R,U,D;
		cin>>U>>L>>D>>R;
		第44题;
		cout<<a[D][R]-a[D][L]-a[U][R]第45题<<endl;
	}
	return 0;
}

41处该填{{ select(41) }}

  • a[i-1][j-1]
  • a[i-1][j]
  • a[i][j-1]
  • a[i][j]

42处该填{{ select(42) }}

  • int i=1;i<=n;i++
  • int i=n;i>=1;i--
  • int j=1;j<=n;j++
  • int j=n;j>=1;j--

43处该填{{ select(43) }}

  • int i=1;i<=n;i++
  • int i=n;i>=1;i--
  • int j=1;j<=n;j++
  • int j=n;j>=1;j--

44处该填{{ select(44) }}

  • U--,L--;
  • U--,R--;
  • D--,L--;
  • D--,R--;

45处该填{{ select(45) }}

  • -a[U][L]
  • +a[U][L]
  • -a[U+1][L+1]
  • +a[U+1][L+1]

程序C: 使用插入排序对数组a从小到大排序

#include<bits/stdc++.h>
using namespace std;
int a[100];
int n;
void insert_sort(int pos){
	if(第46题) return;
	insert_sort(pos-1);
	int temp=a[pos];
	int j=第47题;
	while(48题){
		a[j+1]=a[j];
		j--;
	}
	第49题;
}
int main() {
	srand(time(0));
	n=rand()%100;
	for(int i=0;i<n;i++){
		a[i]=rand()%100;
	}
	insert_sort(第50题);
	for(int i=0;i<n;i++) cout<<a[i]<<' ';
	return 0;
}

46处该填{{ select(46) }}

  • pos>=n
  • pos>n
  • pos<=1
  • pos<1

47处该填{{ select(47) }}

  • pos
  • pos-1
  • pos+1
  • n-1

48处该填{{ select(48) }}

  • j>=0 && temp>=a[j]
  • j<0 && temp>=a[j]
  • j>=0 && temp<a[j]
  • j<0 && temp<a[j]

49处该填{{ select(49) }}

  • swap(a[j],a[j+1])
  • swap(a[j],a[pos])
  • a[j]=temp
  • a[j+1]=temp

50处该填{{ select(50) }}

  • 0
  • 1
  • n-1
  • n