大佬们来看看,本地都是对的,为什么叫上去全RE了??

P1093 [NOIP2007 普及组] 奖学金

hierophant_green @ 2019-11-16 10:27:39

#include<bits/stdc++.h>
using namespace std;
struct node{
    int ch;
    int en;
    int ma;
    int id;
    int tot;
};
bool cmp(node a, node b)
{
    if(a.tot != b.tot)
        return a.tot > b.tot;
    if(a.ch != b.ch)
        return a.ch > b.ch;
    return a.id < b.id;
}
int main(){
    int n;
    cin >> n;
    node a[n];
    for(int i = 1; i <= n; i++){
        cin >> a[i].ch >> a[i].ma >> a[i].en;
        a[i].tot = a[i].ch + a[i].ma + a[i].en;
        a[i].id = i;
    }
    sort(a + 1, a + n + 1, cmp);
    for(int i = 1; i <= 5; i++)
        cout << a[i].id << ' ' << a[i].tot << endl;
    return 0;
} 

by JRzyh @ 2019-11-19 17:30:39

@babyec +8多吉利


by JRzyh @ 2019-11-19 17:43:58

还有,sort排序很稳定。


by JRzyh @ 2019-11-19 17:44:28

大佬都明白


上一页 |