Escapism @ 2021-04-19 17:21:40
大佬求助!第8个测试点!sort + 结构体
程序```cpp
using namespace std;
struct peo{ int ch,ma,en; int mark; int id; } a[305];
bool cmp(peo x,peo y){ if (x.mark != y.mark) return x.mark > y.mark; if (x.mark == y.mark) return x.ch > y.ch; return x.id < y.id; } int main(){ int n; cin>>n; for (int i = 1;i <= n;i++){ cin>>a[i].ch>>a[i].ma>>a[i].en; a[i].mark = a[i].ch + a[i].ma + a[i].en; a[i]id = i; } sort(a,a + n + 1,cmp); for (int i = 1;i <= 5;i++){ cout<<a[i].id<<a[i].mark; } }
by DWT8125 @ 2021-05-05 10:18:44
@112358YC 望丰展?使MD
by Escapism @ 2021-05-14 20:13:52
拉长版的
#include <iostream>
#include <algorithm>
using namespace std;
struct peo{
int ch,ma,en;
int mark;
int id;
} a[305];
bool cmp(peo x,peo y){
if (x.mark != y.mark) return x.mark > y.mark;
if (x.mark == y.mark) return x.ch > y.ch;
return x.id < y.id;
}
int main(){
int n;
cin>>n;
for (int i = 1;i <= n;i++){
cin>>a[i].ch>>a[i].ma>>a[i].en;
a[i].mark = 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].mark<<endl;
}
}
by Moeebius @ 2021-05-20 18:56:00
x.mark==y.mark不代表x.ch!=y.ch