【PAT】B1004 成绩排名(20 分)

#include<cstdio>
#include<malloc.h>
#include<algorithm>
using namespace std;
typedef struct stu {
    char name[14];
    char number[14];
    int score;
}student;
bool cmp(student a,student b){
    return a.score>b.score;
}
int main() {
    int n;
    scanf("%d", &n);
    student *arr = (student *)malloc(sizeof(student)*n);
    for (int i = 0; i<n; i++) {
        scanf("%s %s %d", arr[i].name, arr[i].number, &(arr[i].score));
    }
    sort(arr,arr+n,cmp);
    printf("%s %s",arr[0].name,arr[0].number);
    printf("\n%s %s",arr[n-1].name,arr[n-1].number);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/hebust/p/9498152.html