Problem5148--结构体练习-1

5148: 结构体练习-1

Time Limit: 1.000 Sec  Memory Limit: 128 MB
Submit: 62  Solved: 20
[Submit] [Status] [Web Board] [Creator:]

Description

有若干个学生,每个学生的数据包括学号、姓名、三门课成绩及平均成绩。从键盘输入一个正整数n(1<=n<=100),接着再输入n 行数据,分别代表n个学生数据(学号、姓名、三门课成绩,不包括平均成绩)。在随后的一行上输出n个同学的平均成绩,另起一行输出平均成绩最高的同学的信息(学号、姓名、三门课成绩、平均成绩)。
要求:
1、 定义学生结构体。可参加如下格式:
struct student{
    int  id;                 //学号
    char name[20];   //姓名
    double score[3];  //三门课成绩,取值在0.0-100.0
    double aver;       //平均成绩,保留两位小数
};
要求输出平均分和平均分最高的学生数据。


Input

10
6347 asai 78.5 74.1 44.4
1225 iscp 63.6 71.7 61.0
9071 rkfg 67.0 44.6 33.1
1651 bexn 84.7 59.0 24.1
7110 jylh 83.6 37.4 54.7
2197 gbxs 92.5 86.9 77.7
1488 xxhb 35.1 91.8 72.8
5342 nxqe 46.2 87.1 75.1
9399 gbal 22.2 95.7 73.0
6177 velc 23.4 14.0 82.4

Output

65.67 65.43 48.23 55.93 58.57 85.70 66.57 69.47 63.63 39.93
2197 gbxs 92.5 86.9 77.7 85.70

Sample Input

5
9443 uuhx 78.6 22.2 65.7
5877 bbuv 42.6 83.0 33.2
4561 rxqp 53.9 17.7 26.7
8175 ubgj 77.7 67.6 61.1
8225 obcw 49.9 15.3 72.0

Sample Output

55.50 52.93 32.77 68.80 45.73
8175 ubgj 77.7 67.6 61.1 68.80

HINT

#include<bits/stdc++.h>
usingnamespacestd;
intn,sum,maxn,maxm;
structstudent{
    intid;
    string name;
    doubley,s,i,p;
    doubleaver;
}a[101];
intmain(){
    cin>>n;
    for(inti=0;i<n;i++){
        sum=0;
        cin>>a[i].id>>a[i].name>>a[i].y>>a[i].s>>a[i].i;
        a[i].p=(a[i].y+a[i].s+a[i].i)/3;
        sum+=a[i].y+a[i].s+a[i].i;
        if(sum>maxn){
            maxn=sum;
            maxm=i;
        }
    }
    for(inti=0;i<n;i++){
        printf("%.2lf",a[i].p);
        cout<<" ";
    }
    cout<<endl<<a[maxm].id<<" "<<a[maxm].name<<" "<<a[maxm].y<<" "<<a[maxm].s<<" "<<a[maxm].i<<" ";
    printf("%.2lf",a[maxm].p);
    return0;
}


Source/Category


[Submit] [Status]