#include <iostream>
#define N 100010
using namespace std;
struct Node{
char num[10];
char name[10];
int grade;
};
int n,c;
Node node[N];
int cmp1(const void*a,const void*b){
Node *aa = (Node*)a;
Node *bb = (Node*)b;
return strcmp(aa->num,bb->num);
}
int cmp2(const void*a,const void*b){
Node *aa = (Node*)a;
Node *bb = (Node*)b;
if (strcmp(aa->name,bb->name))
{
return strcmp(aa->name,bb->name);
}else
return strcmp(aa->num,bb->num);
}
int cmp3(const void*a,const void*b){
Node *aa = (Node*)a;
Node *bb = (Node*)b;
if (aa->grade == bb->grade)
{
return strcmp(aa->num,bb->num);
}else
return aa->grade - bb->grade;
}
int main(){
int i,j;
int Case=0;
while (scanf("%d %d",&n,&c)!=EOF)
{
if(n==0&&c==0)break;
for (i=0;i<n;i++)
{
scanf("%s %s %d",&node[i].num,&node[i].name,&node[i].grade);
}
if (c==1)
{
qsort(node,n,sizeof(node[0]),cmp1);
}
else if (c==2)
{
qsort(node,n,sizeof(node[0]),cmp2);
}else if(c==3)
{
qsort(node,n,sizeof(node[0]),cmp3);
}
printf("Case %d:\n",++Case);
for (i=0;i<n;i++)
{
printf("%s %s %d\n",node[i].num,node[i].name,node[i].grade);
}
}
return 0;
}
hdu1862 EXCEL排序
最新推荐文章于 2024-11-13 09:34:08 发布