1 #include<iostream> 2 #include<vector> 3 #include<algorithm> 4 #pragma warning(disable : 4996) 5 6 using namespace std; 7 8 struct student 9 { 10 int sid; 11 int de_grade; 12 int cai_grade; 13 student(int sid, int de_grade, int cai_grade) : sid(sid), de_grade(de_grade), cai_grade(cai_grade) 14 { 15 } //constructor 16 }; 17 18 bool compare(const student &s1, const student &s2) 19 { 20 int total1 = s1.de_grade + s1.cai_grade, total2 = s2.de_grade + s2.cai_grade; 21 if (total1 != total2) 22 return total1 > total2; 23 else 24 if (s1.de_grade != s2.de_grade) 25 return s1.de_grade > s2.de_grade; 26 else 27 return s1.sid < s2.sid; 28 } 29 30 int main() 31 { 32 int N, L, H; 33 cin >> N >> L >> H; 34 int cnt = 0; 35 int sid, de_grade, cai_grade; 36 vector<student> v1, v2, v3, v4; 37 for (int i = 0; i != N; ++i) 38 { 39 scanf("%d%d%d", &sid, &de_grade, &cai_grade); 40 if (de_grade >= L && cai_grade >= L) 41 { 42 ++cnt; 43 if (de_grade >= H && cai_grade >= H) 44 v1.push_back(student(sid, de_grade, cai_grade)); 45 else if (de_grade >= H && cai_grade < H) 46 v2.push_back(student(sid, de_grade, cai_grade)); 47 else if (de_grade < H && cai_grade < H && de_grade >= cai_grade) 48 v3.push_back(student(sid, de_grade, cai_grade)); 49 else 50 v4.push_back(student(sid, de_grade, cai_grade)); 51 } 52 } 53 printf("%d\n", cnt); 54 sort(v1.begin(), v1.end(), compare); 55 for (auto &c : v1) 56 printf("%d %d %d\n", c.sid, c.de_grade, c.cai_grade); 57 sort(v2.begin(), v2.end(), compare); 58 for (auto &c : v2) 59 printf("%d %d %d\n", c.sid, c.de_grade, c.cai_grade); 60 sort(v3.begin(), v3.end(), compare); 61 for (auto &c : v3) 62 printf("%d %d %d\n", c.sid, c.de_grade, c.cai_grade); 63 sort(v4.begin(), v4.end(), compare); 64 for (auto &c : v4) 65 printf("%d %d %d\n", c.sid, c.de_grade, c.cai_grade); 66 67 return 0; 68 }
注意输入输出数据量较大时,不要使用cin与cout,否则会超时