zoukankan      html  css  js  c++  java
  • 第十周项目4-大奖赛计分

    在歌手大奖赛中,有10个评委为参赛的选手打分,分数为0~10分。选手最后得分为:去掉一个最高分和一个最低分后,取其余8个分数的平均值。

    /*
     *Copyright (c) 2014,烟台大学计算机学院
     *All gight reserved.
     *文件名称:temp.cpp
     *作者:邵帅
     *完成时间:2014年11月2日
     *版本号:v1.0
    */
    #include<iostream>
    using namespace std;
    int main()
    {
        double max,min,score,sum,avr;
        int i;
        max=0;
        min=11;
        cout<<"请输入选手的成绩(0-10)"<<endl;
        for (i=1; i<10; i++)
        {
    
            cout<<"请输入第"<<i<<"评委的给分:";
            cin>>score;
            if (score>max)
                max=score;
            if (score<min)
                min=score;
            sum=sum+score;
        }
        avr=(sum-max-min)/8;
        cout<<"去掉一个最高分:"<<max<<" 去掉一个最低分:"<<min<<endl;
        cout<<"当前选手的最后得分是:"<<avr;
        return 0;
    }

    运行结果:



    当评委人数并不固定为10人,修改程序,可以选择在运行开始时输入评委人数。

    /*
     *Copyright (c) 2014,烟台大学计算机学院
     *All gight reserved.
     *文件名称:temp.cpp
     *作者:邵帅
     *完成时间:2014年11月2日
     *版本号:v1.0
    */
    #include<iostream>
    using namespace std;
    int main()
    {
        double max,min,score,sum,avr;
        int i,x;
        max=0;
        min=11;
        cout<<"请输入评委的人数:";
        cin>>x;
        cout<<"请输入选手的成绩(0-10)"<<endl;
        for (i=1; i<=x; i++)
        {
    
            cout<<"请输入第"<<i<<"评委的给分:";
            cin>>score;
            if (score>max)
                max=score;
            if (score<min)
                min=score;
            sum=sum+score;
        }
        avr=(sum-max-min)/8;
        cout<<"去掉一个最高分:"<<max<<" 去掉一个最低分:"<<min<<endl;
        cout<<"当前选手的最后得分是:"<<avr;
        return 0;
    }
    
    运行结果:



    输入的成绩必须在0-10之间,当输入错误时要能马上重新输入,直到输入值在正确的范围内。

    /*
     *Copyright (c) 2014,烟台大学计算机学院
     *All gight reserved.
     *文件名称:temp.cpp
     *作者:邵帅
     *完成时间:2014年11月2日
     *版本号:v1.0
    */
    #include<iostream>
    using namespace std;
    int main()
    {
        double max,min,score,sum,avr;
        int i,x;
        max=0;
        min=11;
        cout<<"请输入评委的人数:";
        cin>>x;
        cout<<"请输入选手的成绩(0-10)"<<endl;
        i=1;
        while(i<=x)
        {
    
            cout<<"请输入第"<<i<<"评委的给分:";
            cin>>score;
            if (score>10||score<0)
                continue;
            if (score>max)
                max=score;
            if (score<min)
                min=score;
            sum=sum+score;
            i++;
        }
        avr=(sum-max-min)/(x-2);
        cout<<"去掉一个最高分:"<<max<<" 去掉一个最低分:"<<min<<endl;
        cout<<"当前选手的最后得分是:"<<avr;
        return 0;
    }
    
    运行结果:



    一次比赛有好几十位选手参加,输出当前选手的最后得分后,提示“按N键退出,其他键继续...”如果输入的不是N或n,可以为下一位选手计算成绩。

    /*
     *Copyright (c) 2014,烟台大学计算机学院
     *All gight reserved.
     *文件名称:temp.cpp
     *作者:邵帅
     *完成时间:2014年11月2日
     *版本号:v1.0
    */
    #include<iostream>
    using namespace std;
    int main()
    {
    
        double max,min,score,sum,avr;
        int i,x;
        char choice;
        max=0;
        min=11;
        while (choice!='N' && choice!='n')
        {
            cout<<"请输入评委的人数:";
            cin>>x;
            cout<<"请输入选手的成绩(0-10)"<<endl;
            i=1;
            while(i<=x)
            {
    
                cout<<"请输入第"<<i<<"评委的给分:";
                cin>>score;
                if (score>10||score<0)
                    continue;
                if (score>max)
                    max=score;
                if (score<min)
                    min=score;
                sum=sum+score;
                i++;
            }
            avr=(sum-max-min)/(x-2);
            cout<<"去掉一个最高分:"<<max<<" 去掉一个最低分:"<<min<<endl;
            cout<<"当前选手的最后得分是:"<<avr<<endl;
            cout<<endl<<"按N退出,其他键继续...";
            cin>>choice;
        }
        return 0;
    }
    运行结果:



    @ Mayuko

  • 相关阅读:
    常见 Web 安全攻防总结
    传统方式接口测试返回值json验证
    Springboot中RestTemplate -- 用更优雅的方式发HTTP请求
    mock简单的json返回
    MySQL数据库学习笔记(五)----MySQL字符串函数、日期时间函数
    MySQL数据库学习笔记(四)----MySQL聚合函数、控制流程函数(含navicat软件的介绍)
    MySQL数据库学习笔记(三)----基本的SQL语句
    MySQL数据库学习笔记(一)----MySQL 5.6.21的安装和配置(setup版)
    python实现广度优先搜索
    php递归
  • 原文地址:https://www.cnblogs.com/mayuko/p/4567644.html
Copyright © 2011-2022 走看看