EXCEL排序
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11824 Accepted Submission(s): 4705
行,每行包含一条学生纪录。每条学生纪录由学号(6位数字,同组测试中没有重复的学号)、姓名(不超过8位且不包含空格的字符串)、成绩(闭区间[0, 100]内的整数)组成,每个项目间用1个空格隔开。当读到 N=0 时,全部输入结束,相应的结果不要输出。
时,按成绩的非递减排序。当若干学生具有相同姓名或者相同成绩时,则按他们的学号递增排序。
3 1 000007 James 85 000010 Amy 90 000001 Zoe 60 4 2 000007 James 85 000010 Amy 90 000001 Zoe 60 000002 James 98 4 3 000007 James 85 000010 Amy 90 000001 Zoe 60 000002 James 90 0 0
Case 1: 000001 Zoe 60 000007 James 85 000010 Amy 90 Case 2: 000010 Amy 90 000002 James 98 000007 James 85 000001 Zoe 60 Case 3: 000001 Zoe 60 000007 James 85 000002 James 90 000010 Amy 90
#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;
}