排序问题:
复制代码
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
43
44
45
46
47#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> using namespace std; const int maxn=100005; int n,c; struct stu{ char num[10]; char s[10]; int score; }; stu st[maxn]; int compare(stu a,stu b) { if(c==1){ return strcmp(a.num,b.num)<0; } else if(c==2){ if(strcmp(a.s,b.s)){ return strcmp(a.s,b.s)<0; } else{ return strcmp(a.num,b.num)<0; } } else{ if(a.score!=b.score){ return a.score<b.score; } else{ return strcmp(a.num,b.num)<0; } } } int main() { scanf("%d%d",&n,&c); for (int i=0;i<n;i++) scanf("%s %s %d",st[i].num,&st[i].s,&st[i].score); sort(st,st+n,compare); for (int i=0;i<n;i++) printf("%s %s %dn",st[i].num,st[i].s,st[i].score); return 0; }
最后
以上就是羞涩睫毛最近收集整理的关于PTA数据结构与算法题目集(中文)7-37的全部内容,更多相关PTA数据结构与算法题目集(中文)7-37内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复