2021-11-01输入n(n<1000),并输入n 个学生的分数(百分制,整数,0-100),统计哪个分数出现次数最多,如有多个并列,从小到大输出。

本文介绍了一个C++程序,用于找出数组中出现次数最多的重复整数。通过两层循环遍历数组,程序记录每个整数出现的频率,并最终输出出现次数最多的整数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <iostream>
using namespace std;

int main() {
	int m, n, x, count = 1;
	int k, temp, maxcount = 0;
	cin >> n;
	int a[1000] = {0};
	int b[101] = {0};
	for (int i = 0; i < n; i++) {
		cin >> x;
		a[i] = x;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (a[i] == a[j] && i != j) {
				b[a[i]]++;
			}
		}
		if (maxcount <= b[a[i]]) {
			maxcount = b[a[i]];
		}
	}
	for (int i = 0; i < n; i++) {
		if (b[i] == maxcount) {
			cout << i;
		}
	}
	return 0;
}

为了编写程序统计N个学生百分制成绩转化为五制成绩的布,我们可以按照以下步骤: 1. 首先,我们需要创建一个数据结构来存储每个分数段的学生人数,比如一个长度为5的整数数组,别对应0-59、60-69、70-79、80-89和90-100五个等级。 2. 程序会从用户那里获取输入,循环N次,每次读取一个学生百分制成绩。 3. 将每个百分制成绩映射到相应的五制区间。例如: - 如果成绩小于等于59,记为0- 60-69记为1- 70-79记为2- 80-89记为3- 90-100记为4。 4. 更新对应区间的计数。遍历整个数组找到对应的索引增加该位置的值。 5. 循环结束后,这个数组就反映了所有学生制成绩的布情况。 下面是一个简单的Python示例代码: ```python def convert_scores_to_fives(n, scores): grade_distribution = [0] * 5 for score in scores: if score >= 0 and score <= 59: grade_distribution[0] += 1 elif score >= 60 and score <= 69: grade_distribution[1] += 1 elif score >= 70 and score <= 79: grade_distribution[2] += 1 elif score >= 80 and score <= 89: grade_distribution[3] += 1 else: grade_distribution[4] += 1 return grade_distribution n = int(input("请输入学生总数:")) scores = [] for _ in range(n): score = int(input(f"请输入第{_[0]+1}名学生百分制成绩:")) scores.append(score) fives_distribution = convert_scores_to_fives(n, scores) print("五制成绩布:", fives_distribution) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值