1028. List Sorting (25)
来源:互联网 发布:苹果频谱电脑软件 编辑:程序博客网 时间:2024/06/05 15:51
1. 原题: https://www.patest.cn/contests/pat-a-practise/1028
2. 思路:
排序问题。注意不要用string表示名字,会超时
同时I/O用printf和scanf。
同时I/O用printf和scanf。
3. 源码(已AC):
#include<iostream>#include<algorithm>//使用sort函数#include<cstring>//使用strcmp函数using namespace std;struct Stu{bool operator<(const Stu &b) const//重载比较运算符,也可以单独写个比较函数{return id < b.id;}int id;char name[9];int score;};bool Cmp2(const Stu &a, const Stu &b);//按名字字典序排序bool Cmp3(const Stu &a, const Stu &b);//按分数排序int main(){freopen("in.txt", "r", stdin);int N, C;scanf("%d %d", &N, &C);Stu *student = new Stu[N];for (int i = 0; i < N; i++)scanf("%d %s %d", &student[i].id, &student[i].name, &student[i].score);switch(C){case 1:sort(student, student+N);break;case 2:sort(student, student+N, Cmp2);break;default:sort(student, student+N, Cmp3);break;}for (int i = 0; i < N; i++)printf("%06d %s %d\n", student[i].id, student[i].name, student[i].score);delete[] student;return 0;}bool Cmp2(const Stu &a, const Stu &b)//按名字字典序排序{if (strcmp(a.name, b.name) == 0)return a.id < b.id;elsereturn strcmp(a.name, b.name) < 0;}bool Cmp3(const Stu &a, const Stu &b)//按分数排序{if (a.score == b.score)return a.id < b.id;elsereturn a.score < b.score;}
0 0
- 1028. List Sorting (25)
- 1028. List Sorting (25)
- 1028. List Sorting (25)
- 1028. List Sorting (25)
- 1028. List Sorting (25)
- 1028. List Sorting (25)
- 1028. List Sorting (25)
- 1028. List Sorting (25)
- 1028. List Sorting (25)
- 1028. List Sorting (25)
- 1028. List Sorting (25)
- 1028. List Sorting (25)
- 1028. List Sorting (25)
- 1028. List Sorting (25)
- 1028. List Sorting (25)
- 1028. List Sorting (25)
- 1028. List Sorting (25)
- 1028. List Sorting (25)
- 滑动时收起键盘
- HiHoCoder1033交错和——数位dp
- 基带传输与成形滤波
- Linux下web服务器搭建需注意的问题
- 树莓派使用触摸开关上手初体验
- 1028. List Sorting (25)
- 实现一个类 Vue 的 MVVM 框架
- 以字分词最大熵模型
- The xor-longest Path ( POJ - 3764)
- 实时Linux进程间的通信
- 升余弦滤波器与根升余弦滤波器
- 实现一个类 Vue 的 MVVM 框架_0
- 简单web服务器的设计与实现
- 磁盘文件操作_ZwCreateFile_ZwOpenFile_ZwReadFile_ZwWriteFile_ZwSetInformationFile_ZwQueryInformationFile