Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11824 Accepted Submission(s): 4705
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int C;
struct ssss
{
char a[10],b[10];
int c;
}ss[111111];
bool cmp(const ssss &a,const ssss &b)
{
if(C==1)
if(strcmp(a.a,b.a)<0)return 1;
else return 0;
else if(C==2)
if(strcmp(a.b,b.b)<0||strcmp(a.b,b.b)==0&&strcmp(a.a,b.a)<0)return 1;
else return 0;
else if(C==3)
if(a.c<b.c||a.c==b.c&&strcmp(a.a,b.a)<0)return 1;
else return 0;
}
int main (void)
{
int n,i,j,k=1,l;
while(scanf("%d%d",&n,&C)!=EOF&&n)
{
for(i=0;i<n;i++)
scanf("%*c%s%s%d",ss[i].a,ss[i].b,&ss[i].c);
sort(ss,ss+n,cmp);
printf("Case %d:\n",k++);
for(i=0;i<n;i++)
printf("%s %s %d\n",ss[i].a,ss[i].b,ss[i].c);
}
return 0;
}