-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy path3.2.cpp
42 lines (35 loc) · 1.08 KB
/
3.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
33
34
35
36
37
38
39
40
41
42
/*
* 题目名称:成绩排序
* 题目来源:清华大学复试上机题
* 题目链接:http://t.cn/E9d3ysv
* 代码作者:杨泽邦(炉灰)
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN = 100 + 10;
struct Student {
int number; //学号
int score; //成绩
};
Student arr[MAXN];
bool Compare(Student x, Student y) { //比较函数
if (x.score == y.score) { //成绩相等比较学号
return x.number < y.number;
} else { //成绩不等比较成绩
return x.score < y.score;
}
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d%d", &arr[i].number, &arr[i].score);
}
sort(arr, arr + n, Compare); //按照比较函数排序
for (int i = 0; i < n; ++i) {
printf("%d %d\n", arr[i].number, arr[i].score);
}
return 0;
}