B1004 成绩排名

C

#include <stdio.h>

struct Student{
    char name[11];
    char id[11];
    int score;
}temp, stuMax, stuMin;

int main()
{
    int n;
    scanf("%d",&n);
    stuMax.score = 0;
    stuMin.score = 100;
    for(int i=0; i<n; i++)
    {
        scanf("%s %s %d",&temp.name,&temp.id,&temp.score);
        if(temp.score>stuMax.score) stuMax=temp;
        if(temp.score<stuMin.score) stuMin=temp;
    }
    printf("%s %s\n",stuMax.name,stuMax.id);
    printf("%s %s\n",stuMin.name,stuMin.id);
    return 0;
}

C++

#include <iostream>
using namespace std;

void fun(int n)
{
    int max=0,min=100,score=0;
    string maxName, maxId;
    string minName, minId;
    string name, id;
    for(int i=0; i<n; i++)
    {
        cin >> name >> id >> score;
        if(score>max)
        {
            maxName = name;
            maxId = id;
            max = score;
        }
        if(score<min)
        {
            minName = name;
            minId = id;
            min = score;
        }
    }
    cout << maxName << ' ' << maxId << endl;
    cout << minName << ' ' << minId << endl;
}

int main()
{
    int n=0;
    scanf("%d",&n);
    fun(n);
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值