标签:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct Student
{
char ID[10];
char name[10];
int gread;
}STU[100010];
bool cmp1(Student a,Student b)
{
return strcmp(a.ID,b.ID)<0;
}
bool cmp2(Student a,Student b)
{
if(strcmp(a.name,b.name)!=0)
return strcmp(a.name,b.name)<0;
else
return strcmp(a.ID,b.ID)<0;
}
bool cmp3(Student a,Student b)
{
if(a.gread!=b.gread)
return a.gread<b.gread;
else
return strcmp(a.ID,b.ID)<0;
}
int main()
{
int n,accord;
scanf("%d%d",&n,&accord);
for(int i=0 ; i<n ; ++i)
{
scanf("%s %s %d",&STU[i].ID, &STU[i].name, &STU[i].gread);
}
if(accord==1)
sort(STU,STU+n,cmp1);
if(accord==2)
sort(STU,STU+n,cmp2);
if(accord==3)
sort(STU,STU+n,cmp3);
for(int i=0 ; i<n ; ++i)
printf("%s %s %d\n",STU[i].ID,STU[i].name,STU[i].gread);
return 0;
}
PAT:1028. List Sorting (25) AC
标签:
原文地址:http://www.cnblogs.com/Evence/p/4307547.html