打印成绩表
2023-08-17 09:24:04
发布于:广东
#include <bits/stdc++.h>
using namespace std;
struct student{
string name;
int grade;
}a[101];
bool cmp(student x, student y) {
return x.grade > y.grade;
}
int main(){
freopen("sort.in","r",stdin);
freopen("sort.out","w",stdout);
int n;
cin>>n;
for (int i = 1; i <= n; i++) {
cin>>a[i].name>>a[i].grade;
}
sort(a+1,a+1+n,cmp);
for(int i = 1; i <= n; i++){
cout<<a[i].name<<" "<<a[i].grade<<endl;
}
fclose(stdin);
fclose(stdout);
return 0;
}
这里空空如也
有帮助,赞一个