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

  • Post author:
  • Post category:其他


#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;
}



版权声明:本文为RicardoLJX原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。