PAT (Basic Level) Practice (中文)1004 成绩排名 (20 分)
题目链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805321640296448
1 #include <iostream> 2 #include <cstdio> 3 #include <string> 4 #include <cstring> 5 #include <algorithm> 6 #include <stack> 7 using namespace std; 8 int n; 9 struct stu 10 { 11 char name[15]; 12 char number[15]; 13 int score; 14 }a[1005]; 15 int cmp(stu x,stu y) 16 { 17 return x.score>y.score; 18 } 19 int main() 20 { 21 while(scanf("%d",&n)!=EOF){ 22 for(int i=0;i<n;i++){ 23 scanf("%s%s%d",&a[i].name,&a[i].number,&a[i].score); 24 } 25 sort(a,a+n,cmp); 26 printf("%s %s\n",a[0].name,a[0].number); 27 printf("%s %s\n",a[n-1].name,a[n-1].number); 28 } 29 return 0; 30 }