1028 List Sorting (25 分)
大水题。。。
const int N=1e5+10;
struct Node
{
string id;
string name;
int grade;
}a[N];
int n,m;
bool cmp1(Node &a,Node &b)
{
return a.id < b.id;
}
bool cmp2(Node &a,Node &b)
{
if(a.name == b.name) return a.id < b.id;
return a.name < b.name;
}
bool cmp3(Node &a,Node &b)
{
if(a.grade == b.grade) return a.id < b.id;
return a.grade < b.grade;
}
int main()
{
ios;
cin>>n>>m;
for(int i=0;i<n;i++)
cin>>a[i].id>>a[i].name>>a[i].grade;
if(m == 1) sort(a,a+n,cmp1);
else if(m == 2) sort(a,a+n,cmp2);
else sort(a,a+n,cmp3);
for(int i=0;i<n;i++)
cout<<a[i].id<<' '<<a[i].name<<' '<<a[i].grade<<endl;
//system("pause");
return 0;
}