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

  • 相关阅读:
    python中的特殊函数__call__
    python的内存机制
    tf.train.Saver()-tensorflow中模型的保存及读取
    修改过的bug
    JQuery的attr 与 val区别及使用
    多线程处理同一个List测试dome
    synchronized 使用总结
    oracle 自定义函数
    第一天写博客,分享下学习oracle存储过程的过程
    SqlServer
  • 原文地址:https://www.cnblogs.com/mayuko/p/4567644.html
Copyright © 2011-2022 走看看