题解 | #统计成绩#
统计成绩
https://www.nowcoder.com/practice/cad8d946adf64ab3b17a555d68dc0bba
#include <iomanip> #include <iostream> #include <vector> #include <algorithm> #include <numeric> using namespace std; int main() { int a,num=0; float b,total,aver; vector<float> v1; cin>>a; for(int i=0;i<a;i++) { cin>>b; v1.push_back(b); } sort(v1.begin(),v1.end()); total = accumulate(v1.begin(),v1.end(),0.0);//这里的初始值必须定义为float型,后续才会将小数计入 aver = total/v1.size(); cout<<setprecision(2)<<fixed<<*(v1.end()-1)<<" "<<*v1.begin()<<" "<<aver; } // 64 位输出请用 printf("%lld")