中国电子学会(CEIT)2023年09月真题C语言软件编程等级考试一级(含解析答案)

这篇文章提供了中国电子学会C语言软件编程一级2023年9月考试的部分题目,涉及日期格式化、算术表达式计算、判断学生是否有一门课不及格、特殊数字求和以及找到小于给定数的最大质数等C语言编程练习。

中国电子学会(CEIT)考评中心历届真题(含解析答案)

C语言软件编程等级考试一级 2023年09月

编程题五道							总分:100分

一、日期输出(20分)
给定两个整数,表示一个日期的月和日。请按照“MM-DD”的格式输出日期,即如果月和日不到2位时,填补0使得满足2位。
时间限制: 10000
内存限制: 65536
输入
2个整数m, d (0 < m <= 12,0 <d <= 31)。数据保证日期合法。输出
按照题目要求输出日期
样例输入

7 18

样例输出

07-18
#include <iostream>
using namespace std;
int main() {
	int m,d;
	cin >> m >> d;
	if(m<10)
		cout<<"0";
		cout<<m<<"-";
	if(d<10)
		cout<<"0";
		cout<<d;
	return 0;
}

#include <stdio.h>
int main(){
	int m,d;
	scanf("%d %d",&m,&d);
	printf("%02d-%02d",m,d);
	return 0;
}

二、计算(a+b)*(c-b)的值(20分)
给定3个整数a、b、c,计算表达式(a+b)*(c-b)的值。
时间限制: 10000
内存限制: 65536
输入
输入仅一行,包括三个整数a、b、c,数与数之间以一个空格分开。( - 10,000 < a、b、c< 10,000)
输出
输出一行,即表达式的值
样例输入

2 3 5

样例输出

10
#include <iostream>
using namespace std;
int main(){
	int a,b,c;
	cin >> a >> b >> c;
	cout << (a+b)*(c-b);
	return 0;
}

#include <stdio.h>
int main(){
	int a,b,c;
	scanf("%d %d %d" ,&a,&b,&c);
	printf("%d" ,(a+b)*(c-b));
	return 0;
}

三、有一门课不及格的学生(20分)
给出一名学生的语文和数学成绩,判断他是否恰好有一门课不及格(成绩小于60分)。
时间限制: 10000
内存限制: 65536
输入
一行,包含两个在0到100之间的整数,分别是该生的语文成绩和数学成绩。输出
若该生恰好有一门课不及格,输出1;否则输出0。
样例输入

50 80

样例输出

1
#include <iostream>
using namespace std;
int main(){
	int a,b;
	cin >> a >> b;
	if((a<60 && b>=60) || (b<60 && a>=60))
		cout<<1;
	else
		cout<<0;
	return 0;
}

#include <stdio.h>
int main(){
	int a,b;
	scanf("%d %d" ,&a,&b);
	if((a<60 && b>=60) || (b<60 && a>=60))
		printf("1");
	else
		printf("0");
	return 0;
}


四、特殊求和(20分)
如果一个数能够被7整除或者十进制表示中含有数字7,那么我们称这个数为幻数,比如17,21,73是幻数,而6,59不是。对于给定的N,求出1-N中所有幻数的和。
时间限制: 10000
内存限制: 65536
输入
一个整数N(1<N <10000)输出
一个整数,表示1~N中所有幻数的和。
样例输入

14

样例输出

21
#include <iostream>
using namespace std;
int main() {
	int i,n,k,s=0;
	cin >> n;
	for(i=7; i<=n; i++){
		if(i%7==0){
			s+=i;
		}
		else{
			k=i;
			while(k){
				if(k%10==7){
					s+=i;
					break;
				}
				k/=10;
			}
		}
	}
	cout<<s;
	return 0;
}

#include <stdio.h>
int main(){
	int i,n,k,s=0;
	scanf("%d",&n);
	for(i=7; i<=n; i++){
		if(i%7==0){
			s+=i;
		} 
		else{
			k=i;
			while(k){
				if(k%10==7){
					s+=i;
					break;
				}
				k/=10;
			}
		}
	}
	printf("%d",s);
	return 0;
}

五、比n小的最大质数(20分)
对于给定的n,求比n小的质数中最大的一个。
质数是指一个大于1的自然数,除了1和它自身外,不能被其他自然数整除的数。
时间限制: 10000
内存限制: 65536
输入
一个整数n。(2<n< 10000)输出
一个整数,即题目要求的解。
样例输入

100

样例输出

97
#include <iostream>
using namespace std;
int main(){
	int i,j,n;
	cin >> n;
	for(i=n-1; i>1; i--){
		for(j=2; j<=i/2; j++){
			if(i%j==0)
				break;
		}
		if(j>=i/2){
			cout<<i;
			break;
		}
	}
	return 0;
}

#include <stdio.h>
int main(){
	int i,j,n;
	scanf("%d" ,&n);
	for(i=n-1; i>1; i--){
		for(j=2; j<=i/2; j++){
			if(i%j==0)
			break;
		}
		if(j>=i/2){
			printf("%d" ,i);
			break;
			}
		}
	return 0;
}

### 关于电子学会C语言等级考试真题 #### 一级真题分析 以下是基于中国电子学会CEIT)202403月发布的C语言软件编程等级考试一级的一道典型题目及其解答[^1]: ```c #include <stdio.h> int main() { int a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d); printf("%d %d %d %d\n", d, c, b, a); return 0; } ``` 此程序的功能是从标准输入读取四个整数并按逆序输出。这是一级考试中的基础操作,主要考察考生对变量定义、基本输入/输出函数以及简单逻辑的理解。 --- #### 四级真题分析 对于更高级别的四级考试,试题难度显著提升,涉及算法设计与复杂数据结构的应用。以下是一个典型的四级考题案例解析[^2]: **问题描述**: 给定一组数组,通过删除某些特定位置的元素后,统计剩余数组中有多少个元素保持在其原始索引位置上。 **解决方案**: 假设初始数组为 `arr`,长度为 `n`,目标是计算经过指定删除操作后的结果。可以通过模拟删除过程来实现这一功能。 ```c #include <stdio.h> #define MAX_SIZE 100 void remove_elements(int arr[], int n, int indices_to_remove[], int m) { int new_arr[MAX_SIZE], index = 0; for (int i = 0; i < n; ++i) { bool should_keep = true; for (int j = 0; j < m; ++j) { if ((indices_to_remove[j] - 1) == i) { // Adjusting to zero-based indexing should_keep = false; break; } } if (should_keep) { new_arr[index++] = arr[i]; } } // Count elements that are at their original positions after removal. int count_in_place = 0; for (int i = 0; i < index; ++i) { if (new_arr[i] == i + 1) { // Check if element is in its position count_in_place++; } } printf("Number of elements in place: %d\n", count_in_place); } int main() { int arr[] = {1, 2, 3, 4, 5}; int size = sizeof(arr) / sizeof(arr[0]); int indices_to_remove[] = {1, 4}; // Remove the first and fourth elements int num_indices = sizeof(indices_to_remove) / sizeof(indices_to_remove[0]); remove_elements(arr, size, indices_to_remove, num_indices); return 0; } ``` 该代码实现了从数组中移除指定索引处的元素,并统计剩余数组中哪些元素仍然位于其原本的位置上。这是四级考试中常见的算法类问题之一。 --- #### 总结 以上分别展示了电子学会C语言等级考试一至四级的部分真题特点。一级侧重基础知识掌握,而四级则更加注重综合能力及实际应用技能。
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值