PATB1004 成绩排名(20 分)

Posted hebust

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PATB1004 成绩排名(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("
%s %s",arr[n-1].name,arr[n-1].number);
    return 0;
}

以上是关于PATB1004 成绩排名(20 分)的主要内容,如果未能解决你的问题,请参考以下文章