ACM基础题型学习-1.2

问题 B: 各门课的成绩 课后习题11.5

时间限制: 1 Sec  内存限制: 128 MB
提交: 255  解决: 190
[提交][状态][讨论版][命题人:外部导入]

题目描述

有N个学生,每个学生的数据包括学号、姓名、3门课的成绩,从键盘输入N个学生的数据,要求打印出3门课的总平均成绩,以及最高分的学生的数据(包括学号、姓名、3门课成绩)

输入

学生数量N占一行每个学生的学号、姓名、三科成绩占一行,空格分开。

输出

各门课的平均成绩 最高分的学生的数据(包括学号、姓名、3门课成绩)

样例输入

2
1 blue 90 80 70
b clan 80 70 60

样例输出

85 75 65
1 blue 90 80 70

代码如下:

#include <iostream>
using namespace std;

struct student{
    char xh[20];
    char name[20];
    double yu,sx,yy;
}stu[200];      //这样是全局变量


int main()
{
    int s1=0,s2=0,s3=0,total=0,maxtot=0,maxindex=-1;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>stu[i].xh>>stu[i].name>>stu[i].yu>>stu[i].sx>>stu[i].yy;
        s1 = s1+stu[i].yu;
        s2 = s2+stu[i].sx;
        s3 = s3+stu[i].yy;
        total = stu[i].yu+stu[i].sx+stu[i].yy;
        if(total>maxtot){
            maxtot=total;
            maxindex = i;

        }
        //scanf()
    }
    s1= s1/(n);
    s2= s2/(n);
    s3= s3/(n);
    //student stu[200];     另一种定义方式,到底哪种方式好
    cout <<s1<<" "<<s2<<" "<<s3<< endl;
    cout <<stu[maxindex].xh<<" "<<stu[maxindex].name<<" "<<stu[maxindex].yu<<" "<<stu[maxindex].sx<<" "<<stu[maxindex].yy<< endl;
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值