AcWing 429. 獎學金
題意:
按照總分先排序;
若相等,按照語文排序,
若相等, 按照學號升序排序,
思路:
結構體sort一下就好了,
注意要不等時,才到下個if
AC
# include <bits/stdc++.h>
using namespace std;
struct stu{
int m, c, e;
int id, tot;
bool operator < (const stu x)const{
if(tot!=x.tot)return tot>x.tot;
else if(c!=x.c)return c>x.c;
else return id<x.id;
}
} p[340];
int main(){
int n;
cin>>n;
for(int i = 1; i <= n; i ++ ){
int c, m, e;
cin>>c>>m>>e;
p[i]={m,c,e,i,c+m+e};
// cout<<p[i].tot<<endl;
}
sort(p+1,p+1+n);
for(int i = 1; i <= 5; i ++ )cout<<p[i].id<<' '<<p[i].tot<<endl;
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/250124.html
標籤:其他
上一篇:自動機與形式語言復習:文法,DFA,NFA與正則運算式,CFG化簡
下一篇:如何讓編程水平變得更高
