EXCEL排序
代码语言:javascript复制#include<algorithm>
#include<stdio.h>
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 %dn",ss[i].a,ss[i].b,ss[i].c);
}
return 0;
}