C++ 代码实现语文成绩统计与排序
#include
using namespace std;
int main() { int N; cin >> N;
vector<int> scores(N);
for (int i = 0; i < N; i++) {
cin >> scores[i];
}
// 计算总分
int total = 0;
for (int i = 0; i < N; i++) {
total += scores[i];
}
// 计算平均分
double average = (double)total / N;
// 按成绩高低排序
sort(scores.begin(), scores.end(), greater<int>());
// 输出结果
cout << total << endl;
cout << fixed << setprecision(2) << average << endl;
for (int i = 0; i < N; i++) {
cout << scores[i] << " ";
}
cout << endl;
return 0;
}
输入样例:
5
80 90 70 85 95
输出样例:
420
84.00
95 90 85 80 70
原文地址: https://www.cveoy.top/t/topic/qrtz 著作权归作者所有。请勿转载和采集!