-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoj1023.2.cpp
32 lines (32 loc) · 883 Bytes
/
oj1023.2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define MAX 100000
struct Stu{
char id[7];//学号,姓名,成绩
char name[9];
short g;
};
Stu stu[MAX];
bool cmp1(Stu x, Stu y) { return strcmp(x.id, y.id)<0;}
bool cmp2(Stu x, Stu y) { return strcmp(x.name, y.name)<0;}
bool cmp3(Stu x, Stu y) { return x.g<y.g;}
int main()
{
int n, c, k=1;
while(scanf("%d %d\n", &n, &c), n)
{
for(int i=0; i<n; i++) { scanf("%s %s %d\n", stu[i].id, stu[i].name, &stu[i].g);}
sort(stu, stu+n, cmp1);
switch(c)
{
case 1:break;
case 2:stable_sort(stu, stu+n, cmp2);break;
case 3:stable_sort(stu, stu+n, cmp3);break;
}
printf("Case %d:\n", k++);
for(int i=0; i<n; i++) { printf("%s %s %d\n", stu[i].id, stu[i].name, stu[i].g);}
}
return 0;
}