题目链接:1028 List Sorting
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, c;
struct Stu{
string id, name, score;
};
int cmp1(Stu &s1, Stu &s2){
return s1.id < s2.id;
}
int cmp2(Stu &s1, Stu &s2){
if(s1.name == s2.name) return s1.id < s2.id;
return s1.name < s2.name;
}
int cmp3(Stu &s1, Stu &s2){
if(s1.score == s2.score) return s1.id < s2.id;
return s1.score < s2.score;
}
int main(){
cin >> n >> c;
vector<Stu> vs;
for(int i = 0; i < n; i++){
Stu s;
cin >> s.id >> s.name >> s.score;
vs.push_back(s);
}
switch (c) {
case 1:
sort(vs.begin(),vs.end(),cmp1);
break;
case 2:
sort(vs.begin(),vs.end(),cmp2);
break;
case 3:
sort(vs.begin(),vs.end(),cmp3);
break;
}
for(int i = 0; i < n; i++){
printf("%s %s %s\n", vs[i].id.c_str(), vs[i].name.c_str(), vs[i].score.c_str());
}
}