题目描述
小蓝给学生们组织了一场考试,卷面总分为100 分,每个学生的得分都是一个0 到100 的整数。 如果得分至少是60 分,则称为及格。如果得分至少为85 分,则称为优秀。 请计算及格率和优秀率,用百分数表示,百分号前的部分四舍五入保留整数。
输入格式
输入的第一行包含一个整数n,表示考试人数。 接下来n 行,每行包含一个0 至100 的整数,表示一个学生的得分。
输出格式
输出两行,每行一个百分数,分别表示及格率和优秀率。 百分号前的部分四舍五入保留整数。
分别计算几个人数和优秀人数,然后计算比例即可. 参考代码:
#include <bits/stdc++.h>
using ll = long long;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::vector<int> a(n);
for (auto &c : a) {
std::cin >> c;
}
std::sort(a.begin(), a.end());
int exc = n - (std::lower_bound(a.begin(), a.end(), 85) - a.begin());
int pass = n - (std::lower_bound(a.begin(), a.end(), 60) - a.begin());
double rate_exc = exc * 1.0 / n;
double rate_pass = pass * 1.0 / n;
std::cout << std::fixed << std::setprecision(0) << rate_pass * 100;
std::cout << "%\n";
std::cout << std::fixed << std::setprecision(0) << rate_exc * 100;
std::cout << "%";
return 0;
}