PAT 1028. List Sorting
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm> using namespace std; class Stu {
public:
char id[];
char name[];
char grade;
}; bool cmp_id(const Stu* a, const Stu* b) {
return strcmp(a->id, b->id) < ;
} bool cmp_name(const Stu* a, const Stu* b) {
int res = strcmp(a->name, b->name);
if (res > ) {
return false;
} else if (res < ) {
return true;
}
return cmp_id(a, b);
} bool cmp_grade(const Stu* a, const Stu* b) {
if (a->grade > b->grade) {
return false;
} else if (a->grade < b->grade) {
return true;
}
return cmp_id(a, b);
} int main() {
int N, C;
scanf("%d%d", &N, &C);
vector<Stu*> stus(N, NULL); for (int i=; i<N; i++) {
Stu* cur = stus[i] = new Stu();
scanf("%s%s%d", cur->id, cur->name, &(cur->grade));
} // TODO: use function ptr array
if (C==) {
sort(stus.begin(), stus.end(), cmp_id);
} else if (C==) {
sort(stus.begin(), stus.end(), cmp_name);
} else {
sort(stus.begin(), stus.end(), cmp_grade);
} for (int i=; i<N; i++) {
printf("%s %s %d\n", stus[i]->id, stus[i]->name, stus[i]->grade);
}
return ;
}
还是快不起来,那么水的题
PAT 1028. List Sorting的更多相关文章
- PAT 1028 List Sorting[排序][一般]
1028 List Sorting (25)(25 分) Excel can sort records according to any column. Now you are supposed to ...
- PAT 1028 List Sorting (25分) 用char[],不要用string
题目 Excel can sort records according to any column. Now you are supposed to imitate this function. In ...
- PAT 甲级 1028 List Sorting (25 分)(排序,简单题)
1028 List Sorting (25 分) Excel can sort records according to any column. Now you are supposed to i ...
- 【PAT】1028. List Sorting (25)
题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1028 题目描述: Excel can sort records according to an ...
- PAT 甲级 1028. List Sorting (25) 【结构体排序】
题目链接 https://www.patest.cn/contests/pat-a-practise/1028 思路 就按照 它的三种方式 设计 comp 函数 然后快排就好了 但是 如果用 c++ ...
- PAT (Advanced Level) Practice 1028 List Sorting (25 分) (自定义排序)
Excel can sort records according to any column. Now you are supposed to imitate this function. Input ...
- PAT (Advanced Level) 1028. List Sorting (25)
时间卡的比较死,用string会超时. #include<cstdio> #include<cstring> #include<cmath> #include< ...
- PAT甲题题解-1028. List Sorting (25)-水排序
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...
- 【PAT甲级】1028 List Sorting (25 分)
题意: 输入一个正整数N(<=100000)和C(C属于{1,2,3}),接下来输入N行,每行包括学生的六位学号(习惯用string输入,因为可能有前导零),名字和成绩(正整数).输出排序后的信 ...
随机推荐
- 小记 Linux 之 Vim
小记 Linux 之 Vim 使用vim用来进行文本流查询,是非常重要的部分. 技巧一:使用 '#' 系统将列出文档相同字符,在代码时很重要. 技巧二:使用 ']I' 具体操作是先使用 ? 或 \ 进 ...
- screen新建窗口,环境变量跟原来不一致。
昨天为了方便npm安装全局包,我把环境变量重新配置了. 然后,在项目中引用全局包没有出问题.但是后来我在screen里面引用全局包,报错说找不到. 使用#npm list -g命令 发现昨天的全局包都 ...
- mysql 表复制(表备份)
复制一个表数据到新表,我们可以直接执行下面的语句 create table new_table LIKE old_table:--将表结构复制到新表 insert into new_table sel ...
- 2018-2019-2 网络对抗技术 20165314 Exp6 信息搜集与漏洞扫描
一.原理与实践说明 1.实践内容 本实践的目标是掌握信息搜集的最基础技能.具体有: 1.各种搜索技巧的应用 2.DNS IP注册信息的查询 3.基本的扫描技术:主机发现.端口扫描.OS及服务版本探测. ...
- java 使用idea将工程打成jar并创建成exe文件类型执行
https://blog.csdn.net/weixin_38310965/article/details/80392767
- sql查询字段中的值长度最大的记录
SELECT max(length(字段)) FROM 表名;
- archlinux安装tftp
1. 安装 [guo@archlinux ~]$ sudo pacman -S tftp-hpa 2. 启用 [guo@archlinux ~]$ systemctl start tftpd.se ...
- js 删除数组的某一项或者几项的方法
1.arr.splice() splice(index,len,[item]) 注释:该方法会改变原始数组. splice有3个参数,它也可以用来替换/删除/添加数组内某一个或者几个值 inde ...
- 搭建github静态博客
github设置 建立新的repository,命名为OwnerName.github.io,例如gotochenglong.github.io git管理 设置ssh密匙 使用命令ssh-keyge ...
- (转)nginx location在配置中的优先级
原文:https://www.bo56.com/nginx-location%E5%9C%A8%E9%85%8D%E7%BD%AE%E4%B8%AD%E7%9A%84%E4%BC%98%E5%85%8 ...