歌星大赛

来源:互联网 发布:超人软件站官网 编辑:程序博客网 时间:2024/04/30 04:51

//在歌星大奖赛中,有10个评委为参赛的选手打分,分数为1~100分。

//选手最后得分为:去掉一个最高分和一个最低分后其余8个分数的平均值。请编写一个程序实现。

//基本思路:10个元素的数组,找到最大值和最小值并置为0,然后求和 求平均值

//*加上的思考

//题目条件不变,但考虑同时对评委评分进行裁判,即在10个评委中找出最公平(即评分最接返平均分)和最不公平(即与平均分的差距最大)的评委,

//程序应该怎样实现?

//既是求每个元素值跟平均值差值最大与最小的,可以再加一个数组来存放差值数据,然后求出最大值和最小值

#include<iostream>

#include<cmath>

using namespace std;

int main()

    {
      float a[10],sum=0.0,average;

      int i=0;

      int j=0;

      float max,min;

      float max1,min1;

      float b[10];

      int m=0,n=0;//记录下最大最小的坐标,初始化

      cout<<"input the scores of eash judge:"<<endl;

      while(i<10)

          {

            cout<<"the "<<i+1<<"th judge's socre is:"<<endl;
         
            cin>>a[i];

            if(a[i]>100 || a[i]<1)//limit the score

                cout<<"the score is error ,please input again!"<<endl;

            else i++;
         
          }

      //to find the max and min

      max=a[0];

      min=a[0];

      for(i=0;i<10;i++)

          {

            if(a[i]>max)max=a[i];

            if(a[i]<min)min=a[i];

          }
      for(i=0;i<10;i++)

          if(a[i]!=max && a[i]!=min )//drop the max and the min

              sum+=a[i];

          average=sum/8;

          cout<<"the results score which drop the max and the min  of this singer is:"<<average<<endl;

             i=0;j=0;

             while(i<10  && j<10 )

              {

               b[j]=fabs(a[i]-average);

               j++;

               i++;
              
              }

             max1=b[0];

             min1=b[0];


             for(j=0;j<10;j++)

                 {
                  if(b[j]>max1)
                      
                      {max1=b[j];
                        
                        m=j;}

                  if(b[j]<min1)

                      {
                        min1=b[j];

                        n=j;
                      }


                
             }

             cout<<"the longthen of average is: "<<max1

                 <<"it's the "<<m+1<<"th value "
                
                <<"and the score is: "<<a[m]<<endl;

             cout<<"the shorthen of average is: "<< min1

                 <<"it's the  "<<n+1<<"th value "
                 
                 <<"and the score is : "<<a[n]<<endl;
            
                

    return 0;}


从中学习到:数组的元素可以随机访问,变量使用前最好初始化

0 0
原创粉丝点击