c++ 学生成绩排序
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;struct stu{char name[21];int grade;};struct rule{bool operator()(const stu&a1,cons
·
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct stu{
char name[21];
int grade;
};
struct rule{
bool operator()(const stu&a1,const stu&a2)const{
if(a1.grade>a2.grade){
return true;
}
if(a1.grade==a2.grade){
if(strcmp(a1.name,a2.name)<0){
return true;
}
}
return false;
}
};
int main(){
int n;
cin>>n;
stu a[n];
for(int i=0;i<n;i++){
cin>>a[i].name;
cin>>a[i].grade;
}
sort(a,a+n,rule());
for(int i=0;i<n;i++){
cout<<a[i].name<<' '<<a[i].grade<<endl;
}
return 0;
}
更多推荐
已为社区贡献1条内容
所有评论(0)