PAT 1028 List Sorting
include <stdio.h>
include
include <stdlib.h>
include
include
include <string.h>
include
include
include
include
include
include
include <limits.h>
using namespace std;
struct node{
string id, name;
int age;
node(){
}
node(string _id, string _name, int _age){
id = _id;
name = _name;
age = _age;
}
};
node myv[100000 + 10];
bool cmp1(node a, node b){
return a.id < b.id;
}
bool cmp2(node a, node b){
if(a.name < b.name) return true;
else if(a.name == b.name) return a.id < b.id;
else return false;
}
bool cmp3(node a, node b){
if(a.age < b.age) return true;
else if(a.age == b.age) return a.id < b.id;
else return false;
}
int main() {
int N, C;
scanf("%d %d", &N, &C);
for(int i = 0; i < N; i++){
cin >> myv[i].id >> myv[i].name >> myv[i].age;
}
if(C == 1){
sort(myv, myv + N, cmp1);
}
else if(C == 2){
sort(myv, myv + N, cmp2);
}
else{
sort(myv, myv + N, cmp3);
}
for(int i = 0; i < N; i++){
cout << myv[i].id << " " << myv[i].name << " " << myv[i].age << endl;
}
return 0;
}