PAT 甲级 1028 List Sorting
#include<bits/stdc++.h>
using namespace std;
int sort_column;
struct Student
{
string id_;
string name_;
int grades_;
};
bool cmp(const Student &lhs, const Student &rhs)
{
if (sort_column == 3 && lhs.grades_ != rhs.grades_)
return lhs.grades_ < rhs.grades_;
else if (sort_column == 2 && lhs.name_ != rhs.name_)
return lhs.name_ < rhs.name_;
return lhs.id_ < rhs.id_;
}
int main()
{
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int n; cin >> n >> sort_column;
vector<Student> student_set(n);
for (auto &i : student_set)cin >> i.id_ >> i.name_ >> i.grades_;
sort(student_set.begin(), student_set.end(), cmp);
for (auto &i : student_set) {
cout << i.id_ << " " << i.name_ << " " << i.grades_ << endl;
}
}