2 solutions
-
1
有脑写法:
#include<bits/stdc++.h> using namespace std; struct Note{ int Chinese; int maths; int English; int id; int full; }arr[1010]; int n; bool cmp(Note a,Note b){ if(a.full>b.full)return 1; if(a.full==b.full&&a.Chinese>b.Chinese)return 1; if(a.full==b.full&&a.Chinese==b.Chinese&&a.id<b.id)return 1; return 0; } int main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>arr[i].Chinese>>arr[i].maths>>arr[i].English; arr[i].id=i; arr[i].full=arr[i].Chinese+arr[i].maths+arr[i].English; } sort(arr+1,arr+n+1,cmp); for(int i=1;i<=5;i++){ cout<<arr[i].id<<' '<<arr[i].full<<endl; } return 0; } -
0
#include<bits/stdc++.h> using namespace std; struct Node{ int total,id,yuwen,shuxue,yingyu; bool operator<(const Node w)const //大根堆重载小于符号 { if(total<w.total) return 1; if(total==w.total&&yuwen<w.yuwen) return 1; if(total==w.total&&yuwen==w.yuwen&&id>w.id) return 1; return 0; } }; int main() { priority_queue<Node> q; int n; cin>>n; for(int i=1;i<=n;i++) { Node t; cin>>t.yuwen>>t.shuxue>>t.yingyu; t.id=i; t.total=t.yuwen+t.shuxue+t.yingyu; q.push(t); } for(int i=1;i<=5;i++) { Node t=q.top(); q.pop(); cout<<t.id<<" "<<t.total<<endl; } return 0; }
- 1
Information
- ID
- 2132
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 3
- Tags
- # Submissions
- 9
- Accepted
- 8
- Uploaded By