#include "stdafx.h"#include <stdio.h>#include <string.h>#include <stdlib.h> struct student{ char no[7]; char name[9]; int score;}s[100001];
int cmp1(const void *a,const void *b){ struct student *s1,*s2; s1 = (struct student *)a; s2 = (struct student *)b; return strcmp(s1->no,s2->no);}
int cmp2(const void *a,const void *b){ int t; struct student *s1,*s2; s1 = (struct student *)a; s2 = (struct student *)b;
t = strcmp(s1->name,s2->name); if(t == 0) return strcmp(s1->no,s2->no); else return t;
}
int cmp3(const void *a,const void *b){ struct student *s1,*s2; s1 = (struct student *)a; s2 = (struct student *)b; if(s1->score == s2->score) return strcmp(s1->no,s2->no); else return s1->score-s2->score;}
void sort(struct student *s,int n,int c){ int i;
if(c == 1) qsort(s,n,sizeof(struct student),cmp1); else if(c == 2) qsort(s,n,sizeof(struct student),cmp2); else if(c == 3) qsort(s,n,sizeof(struct student),cmp3);
for(i=0;i<n;i++) { printf("%s %s %d/n",s[i].no,s[i].name,s[i].score); }}
int main(int argc, char* argv[]){ int n,c; int i; int caseno = 0;
scanf("%d %d",&n,&c);
while( ! ( n == 0 && c == 0)) { caseno++; for(i=0;i<n;i++) { scanf("%s",s[i].no); scanf("%s",s[i].name); scanf("%d",&s[i].score); } printf("Case %d:/n",caseno); sort(s,n,c);
scanf("%d %d",&n,&c); }
return 0;}