我有个喵喵酱


私信TA

用户名:firstblond

访问量:8648

签 名:

每天都要进步一点点!

等  级
排  名 706
经  验 3910
参赛次数 0
文章发表 19
年  龄 21
在职情况 学生
学  校 家里蹲
专  业

  自我简介:

解题思路:

                    


                        定义不同的变量进行对比,最后输出

注意事项:

参考代码:


            

                        #include<iostream>

                        #include<string>                         //string类
                        using namespace std;
                        struct stu{
                                     int Y,S,E,Z;                    //三门成绩,Z是总分
                                     string name;
                                     char glade;                     //学号
                                            };

                                 int main()
                                 {
                                       int Y,S,E;                          //三个变量为三门学课的成绩平均分
                                       int m,n,i;
                                       Y=S=E=i=0;
                                       cin>>m;
                                       stu x_s[m];                         //创建输入次数大小的结构体
                                        n=m;                                //保存一下大小
                                        while(m--)
                                         {
                                                cin>>x_s[i].glade;
                                                cin>>x_s[i].name;
                                                cin>>x_s[i].Y;
                                                cin>>x_s[i].S;
                                                cin>>x_s[i].E;
                                                Y+=x_s[i].Y;
                                                S+=x_s[i].S;
                                                E+=x_s[i].E;
                                                x_s[i].Z=x_s[i].Y+x_s[i].S+x_s[i].E;    //Z是总分
                                                i++;
                                          }
                                         int G=x_s[0].Z;                                //比较一下然后取出来
                                         for(i=1;i<n;i++)
                                                if(G<x_s[i].Z)
                                                            G=x_s[i].Z;
                                         Y/=n;            //平均成绩
                                         S/=n;
                                         E/=n;
                                         cout<<Y<<" "<<S<<" "<<E<<endl;
                                         for(i=0;i<n;i++)
                                            if(G==x_s[i].Z)                          //取出来和结构体比较          
                                                cout<<x_s[i].glade<<" "<<x_s[i].name<<" "<<x_s[i].Y<<" "<<x_s[i].S<<" "<<x_s[i].E<<endl;

                                    return 0;
                                  }


 

0.0分

0 人评分

  评论区

用到数据结构了吗?
2020-02-20 18:24:16
  • «
  • 1
  • »