题解 | #统计成绩#

统计成绩

https://www.nowcoder.com/practice/cad8d946adf64ab3b17a555d68dc0bba

#include <iomanip>
#include<iostream>
#include<vector>
#include<algorithm>

int main(int argc,char* argv[])
{
    unsigned int n{};
    double score;
    double average{};
    std::vector<double> scores;
    std::cin>>n;
    for(int i{};i<n;i++){
        std::cin>>score;
        scores.push_back(score);  
        std::cin.clear();
    }
  //std::sort(first,last) 对容器或普通数组中 [first, last) 范围内的元素进行排序,默认进行升序排序。
  //ivec.begin()为vector的首地址,end()指向vector容器中尾地址的下一个地址
    std::sort(scores.begin(),scores.end());
  //基于范围的for循环,可以按顺序一个个取出数据
    for(auto arr:scores)
    {
        average+=arr/n;
    }
    std::cout<<std::setiosflags(std::ios::fixed)<<std::setprecision(2)
    <<scores[n-1]<<" "<<*scores.begin()<<" "<<average<<std::endl;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-21 13:41
点赞 评论 收藏
分享
点赞 评论 收藏
分享
07-09 20:50
门头沟学院 Java
码农索隆:1.教育背景和荣誉证书合二为一。 2.获奖项目理一遍,你做了什么,对你求职的岗位有什么帮助,没有就删掉。 3.技能特长和教育背景交换位置。 4.技能特长写的太差,上网上找简历参考。都不用问你别的,一个redis就能把你问住,写写你具体会redis哪些方面的知识。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务