我是靠谱客的博主 哭泣帅哥,这篇文章主要介绍PAT(甲级)1028 List Sorting (25point(s)),现在分享给大家,希望可以做个参考。

题目

题目链接

思路

题目大意:根据不同的排序标准进行排序;
核心就是那三个比较函数;
直接上代码吧,不难理解;

代码

复制代码
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
#include <iostream> #include <string> #include <cstring> #include <vector> #include <algorithm> using namespace std; const int maxn = 1e5 + 10; struct stu{ int id, grade; char name[10]; }v[maxn]; bool cmp1(stu a, stu b){ return a.id < b.id; } bool cmp2(stu a, stu b){ int s = strcmp(a.name, b.name); if(s != 0) return s < 0; else return a.id < b.id; } bool cmp3(stu a, stu b){ if(a.grade != b.grade) return a.grade < b.grade; else return a.id < b.id; } int main() { int n, c; scanf("%d%d", &n, &c); for(int i = 0; i < n; i ++){ scanf("%d %s %d", &v[i].id, v[i].name, &v[i].grade); } if(c == 1) sort(v, v + n, cmp1); else if(c == 2) sort(v, v + n, cmp2); else sort(v, v + n, cmp3); for(int i = 0; i < n; i ++){ printf("%06d %s %dn", v[i].id, v[i].name, v[i].grade); } system("pause"); return 0; }

最后

以上就是哭泣帅哥最近收集整理的关于PAT(甲级)1028 List Sorting (25point(s))的全部内容,更多相关PAT(甲级)1028内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(54)

评论列表共有 0 条评论

立即
投稿
返回
顶部