#include<iostream> using namespace std; #include<vector> #include<string> #include<algorithm> class Student{ public: Student(string name, int age, int score) { this->m_name = name; this->m_age = age; this->m_score = score; } string m_name; int m_age; int m_score; }; bool mycompare(Student s,Student b) { if (s.m_score == b.m_score) { if (s.m_name == b.m_name) { return s.m_age < b.m_age; } return s.m_name < b.m_name; } return s.m_score < b.m_score; } int main() { int N; int age, score; string name; vector<Student> v; while (cin >> N) { //输入学生数据 for (int i = 0; i < N; i++) { cin >> name; cin >> age; cin >> score; Student S(name, age, score); //将学生数据插入到容器中 v.push_back(S); } //自定义排序 sort(v.begin(), v.end(), mycompare); //打印容器内数据 for (vector<Student>::iterator it = v.begin(); it != v.end(); it++) { cout << (*it).m_name << " " << (*it).m_age << " " << (*it).m_score << endl; } v.clear(); } return 0; }
0.0分
0 人评分
用筛法求之N内的素数。 (C语言代码)浏览:807 |
母牛的故事 (C语言代码)浏览:715 |
1012题解浏览:870 |
罗列完美数 (C语言代码)浏览:491 |
字符串的输入输出处理 (C语言代码)浏览:1012 |
数组输出 (C语言代码)浏览:703 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:618 |
小O的数字 (C++代码)浏览:763 |
众数问题 (C语言代码)浏览:630 |
C语言程序设计教程(第三版)课后习题10.2 (C语言代码)浏览:1270 |