文章

2

粉丝

25

获赞

3

访问

262

头像
成绩再次排序 题解:
P1817 华南理工大学机试题
发布于2025年1月14日 16:48
阅读数 110

66%不知道错在什么地方,希望有人帮忙看看,谢谢

 

#include <bits/stdc++.h>
using namespace std;
string s[105];

struct student{
string name;
int yu;
int shu;
int ying;
int sum;
}stu[1005];
bool cmp(student a,student b){
   if(a.sum!=b.sum)return a.sum > b.sum;
   else if(a.yu!=b.yu)return a.yu >b.yu;
   else if(a.shu!=b.shu)return b.shu > b.shu;
   else return a.ying > b.ying;
}
int main(){
   int n;
//   string s;
//   int a,b;
   cin >> n;
  for(int i=0;i<n;i++){
        cin >> stu[i].name;
        cin >> stu[i].yu;
        cin >> stu[i].shu;
        cin >> stu[i].ying;
        stu[i].sum = stu[i].yu+stu[i].shu+stu[i].ying;
    }
    stable_sort(stu,stu+n,cmp);//用stable_sort保持排序的稳定性
    for(int i=0;i<n;i++){
...

登录查看完整内容


登录后发布评论

1 条评论
admin SVIP
2025年1月14日 18:23

赞(0)