您的位置:首页 > 其它

九度OJ学习笔记 题目1023

2017-02-12 12:41 369 查看
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
struct student{
char num[7];
char name[9];
int score;
}buf[100001];
bool cmp1(student a,student b){
return strcmp(a.num,b.num)< 0;
}
bool cmp2(student a,student b){
return strcmp(a.name,b.name)<0;
}
bool cmp3(student a,student b){
return a.score<b.score;
}
int main(){
int N;
int C;
int cnt=1;
while(scanf("%d %d",&N,&C)!=EOF){
if(N==0) break;
for(int i=0;i<N;i++){
scanf("%s %s %d",buf[i].num,buf[i].name,&buf[i].score);
}
sort(buf,buf+N,cmp1);
switch(C){
case 1:
break;
case 2:
stable_sort(buf,buf+N,cmp2);
break;
case 3:
stable_sort(buf,buf+N,cmp3);
break;
}
printf("Case %d:\n",cnt++);
for(int i=0;i<N;i++){
printf("%s %s %d\n",buf[i].num,buf[i].name,buf[i].score);
}

}
return 0;
}

Wrong Answer出现原因:

1. 对于输入 0 0,要求无输出,故应在输入数据之前break;

2. 题目要求当若干学生具有相同姓名或者相同成绩时,则按他们的学号递增排序。故应在switch之前就按cmp1排序。

3. 数据相等时,相对顺序不变。这他也没说,就当隐含要求吧,因为这个我找了一上午bug唉。stable_sort( )。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: