#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 人评分
C语言训练-舍罕王的失算 (C语言代码)浏览:1054 |
母牛的故事 (C语言代码)浏览:782 |
2005年春浙江省计算机等级考试二级C 编程题(3) (C语言代码)浏览:417 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:466 |
C语言程序设计教程(第三版)课后习题10.1 (Java代码)浏览:1492 |
Pascal三角 (C语言代码)格式错误浏览:551 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:552 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:818 |
最小公倍数 (C语言代码)浏览:1105 |
The 3n + 1 problem (C语言代码)浏览:550 |