给定一个百分位数分数T,将其划分为以下五级之一: 90~100为A,80~89为B,70~79为c,60~69为ISD,0~59为EE。 有几个百分位数的分数(分数不超过1000),请数数这五个级别中的人数,找出人数最多的级别,并按降序输出每个人的分数(只有一个级别,人数最多)。 输入:e 第一行是ne级的数目。 第二行是学生的分数,一些正整数从0到100,用空格隔开 产出:e 第一行是5个正整数,重新保留A、B、c、D和EE五层中的人数。 第二行中的正整数表示类中人数最多的人数。 在下一行中用空格分隔的若干正整数c语言
时间: 2023-06-27 10:07:05 浏览: 155
实现代码如下:
```c++
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> scores;
int countA = 0, countB = 0, countC = 0, countD = 0, countE = 0;
for (int i = 0; i < n; i++) {
int score;
cin >> score;
scores.push_back(score);
if (score >= 90 && score <= 100) {
countA++;
} else if (score >= 80 && score <= 89) {
countB++;
} else if (score >= 70 && score <= 79) {
countC++;
} else if (score >= 60 && score <= 69) {
countD++;
} else {
countE++;
}
}
cout << countA << " " << countB << " " << countC << " " << countD << " " << countE << endl;
int maxCount = max({countA, countB, countC, countD, countE});
cout << maxCount << endl;
if (maxCount == countA) {
for (int i = 0; i < n; i++) {
if (scores[i] >= 90 && scores[i] <= 100) {
cout << scores[i] << " ";
}
}
} else if (maxCount == countB) {
for (int i = 0; i < n; i++) {
if (scores[i] >= 80 && scores[i] <= 89) {
cout << scores[i] << " ";
}
}
} else if (maxCount == countC) {
for (int i = 0; i < n; i++) {
if (scores[i] >= 70 && scores[i] <= 79) {
cout << scores[i] << " ";
}
}
} else if (maxCount == countD) {
for (int i = 0; i < n; i++) {
if (scores[i] >= 60 && scores[i] <= 69) {
cout << scores[i] << " ";
}
}
} else {
for (int i = 0; i < n; i++) {
if (scores[i] >= 0 && scores[i] <= 59) {
cout << scores[i] << " ";
}
}
}
return 0;
}
```
输入示例:
```
10
98 85 76 62 45 78 89 91 77 80
```
输出示例:
```
2 2 3 1 2
3
98 91
```
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)