1178_成绩排序(数据排序)
时间限制: 1000 ms 内存限制: 65536 KB
提交数: 18756 通过数: 7478
【题目描述】
给出班里某门课程的成绩单,请你按成绩从高到低对成绩单排序输出,如果有相同分数则名字字典序小的在前。
【输入】
第一行为n (0 < n < 20),表示班里的学生数目;
接下来的n行,每行为每个学生的名字和他的成绩, 中间用单个空格隔开。名字只包含字母且长度不超过20,成绩为一个不大于100的非负整数。
【输出】
把成绩单按分数从高到低的顺序进行排序并输出,每行包含名字和分数两项,之间有一个空格。
【输入样例】
4
Kitty 80
Hanmeimei 90
Joey 92
Tim 28
【输出样例】
Joey 92
Hanmeimei 90
Kitty 80
Tim 28
复制代码
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#include<iostream> #include<algorithm> using namespace std; struct node { char name[21]; int score; }stu[21],temp; int n; int i, j; int main() { cin >> n; for (i = 1; i <= n; ++i) cin >> stu[i].name >> stu[i].score; for(i=1;i<=n;++i) for(j=i+1;j<=n;++j) if (stu[i].score < stu[j].score) { temp = stu[i]; stu[i] = stu[j]; stu[j] = temp; } else if (stu[i].score == stu[j].score && strcmp(stu[i].name, stu[j].name) > 0) { temp = stu[i]; stu[i] = stu[j]; stu[j] = temp; } for (i = 1; i <= n; ++i) cout << stu[i].name << " " << stu[i].score << endl; return 0; }
最后
以上就是专一墨镜最近收集整理的关于1178_成绩排序(数据排序)的全部内容,更多相关1178_成绩排序(数据排序)内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复