游客 Signup | Login
中文 | En

2254 - b1003

使用结构体解决下面问题:输入两个学生的学号、姓名、成绩,输出成绩最高的同学的学号、姓名和成绩。

输入n代表n个学生(学生的姓名不超过200个字符,学号和成绩不大于100)。

数据之间用空格隔开;

Input


Output

Examples

Input

5
1 寒冰射手 38
2 蛮王 20
3 德玛西亚 59
4 光辉女郎 88
5 韦小宝 100

Output

5 韦小宝 100

Hint

本题有点难度,你们要认真。。

Solution C

#include<stdio.h>
struct stu1
{
    int num;
    char a[100];
    double score;

}s[100];
int main()
{
    int n,i,flag=0;
    double max;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d%s%lf",&s[i].num,s[i].a,&s[i].score);
    }

    max=s[0].score;
    for(i=1;i<n;i++)
    {
        if(s[i].score>max)
            {max=s[i].score;
            flag=i;
            }
    }
    if(flag)
    printf("%d %s %.0f\n",s[flag].num,s[flag].a,s[flag].score);
    else printf("%d %s %.0f\n",s[0].num,s[0].a,s[0].score);
}

Solution C++

#include<iostream>
#include<cstdio>
#include<iostream>
#include<cmath>

using namespace std;

int main(){
    int num,score,n;
    string name;
    cin>>n;
    cin>>num>>name>>score;
    for(int i=0;i<n-1;i++){
        int maxscore,x;
        string str;
        cin>>x>>str>>maxscore;
        if(maxscore>score){
            num = x;
            name = str;
            score = maxscore;
        }
        //cout<<i<<endl;
    }
    cout<<num<<' '<<name<<' '<<score<<endl;
    return 0;
}

Hint

本题有点难度,你们要认真。。

Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题