luogu P1093 奖学金
1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 struct stu 5 { 6 int id; 7 int ch; 8 int mth; 9 int eng; 10 friend bool operator < (stu a,stu b) 11 { 12 if ((a.ch + a.mth + a.eng) != (b.ch + b.mth +b.eng)) 13 { 14 if ((a.ch + a.mth + a.eng) < (b.ch + b.mth +b.eng)) 15 return true; 16 else 17 return false; 18 }else if (a.ch != b.ch) 19 { 20 if (a.ch < b.ch) 21 return true; 22 else 23 return false; 24 }else 25 { 26 if (a.id < b.id) 27 return false; 28 else 29 return true; 30 } 31 } 32 }; 33 stu vec[310]; 34 int main() 35 { 36 int n; 37 cin >> n; 38 for (int i = 1;i <= n;i++) 39 { 40 cin >> vec[i].ch >> vec[i].mth >> vec[i].eng; 41 vec[i].id = i; 42 } 43 sort(vec + 1,vec + n + 1); 44 for (int i = n;i >= n - 5 + 1;i--) 45 cout << vec[i].id << " " << vec[i].ch +vec[i].mth +vec[i].eng << endl; 46 }
心之所动 且就随缘去吧