#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的更多相关文章

  1. PAT 1028 List Sorting[排序][一般]

    1028 List Sorting (25)(25 分) Excel can sort records according to any column. Now you are supposed to ...

  2. PAT 1028 List Sorting (25分) 用char[],不要用string

    题目 Excel can sort records according to any column. Now you are supposed to imitate this function. In ...

  3. PAT 甲级 1028 List Sorting (25 分)(排序,简单题)

    1028 List Sorting (25 分)   Excel can sort records according to any column. Now you are supposed to i ...

  4. 【PAT】1028. List Sorting (25)

    题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1028 题目描述: Excel can sort records according to an ...

  5. PAT 甲级 1028. List Sorting (25) 【结构体排序】

    题目链接 https://www.patest.cn/contests/pat-a-practise/1028 思路 就按照 它的三种方式 设计 comp 函数 然后快排就好了 但是 如果用 c++ ...

  6. 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 ...

  7. PAT (Advanced Level) 1028. List Sorting (25)

    时间卡的比较死,用string会超时. #include<cstdio> #include<cstring> #include<cmath> #include< ...

  8. PAT甲题题解-1028. List Sorting (25)-水排序

    #include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...

  9. 【PAT甲级】1028 List Sorting (25 分)

    题意: 输入一个正整数N(<=100000)和C(C属于{1,2,3}),接下来输入N行,每行包括学生的六位学号(习惯用string输入,因为可能有前导零),名字和成绩(正整数).输出排序后的信 ...

随机推荐

  1. 51nod1847 奇怪的数学题 (Min_25筛+第二类斯特林数)

    link \(\sum_{i=1}^n\sum_{j=1}^n\mathrm{sgcd}(i,j)^k=\sum_{p=1}^ns(p)^k\sum_{i=1}^n\sum_{j=1}^n[\gcd( ...

  2. 2016级算法第三次上机-F.ModricWang的导弹防御系统

    936 ModricWang的导弹防御系统 思路 题意即为:给出一个长度为n的序列,求出其最长不降子序列. 考虑比较平凡的DP做法: 令\(nums[i]\) 表示这个序列,\(f[x]\) 表示以第 ...

  3. C#集合之栈

    栈(Stack)和队列是非常类似的一个容器,只是栈是一个后进先出(LIFO)的容器. 栈用Push()方法在栈中添加元素,用Pop()方法获取最近添加的一个元素: Stack<T>与Que ...

  4. EntityFramework First,FirstOrDefault,Single,SingleOrDefault的区别

    操作符 如果源序列是空的 源序列只包含一个元素 源序列包含多个元素 First 抛异常 返回该元素 返回第一个元素 FirstOrDefault 返回default(TSource) 返回该元素 返回 ...

  5. 1-----Docker实例-安装Nginx

    Docker 安装 Nginx 方法一.docker pull nginx(推荐) 查找 Docker Hub 上的 nginx 镜像 runoob@runoob:~/nginx$ docker se ...

  6. Python学习 day12

    一.@wraps __name__    查看函数的名字 __doc__   查看函数的文档字符串 例: def func(arg): """ 这是一个测试函数,这里是函 ...

  7. overload_protect_config.txt

    overload_protection_switch=Y reject_uri_list= reject_request_percent=50 period_time=10 period_max_fa ...

  8. JDK,JRE,JVM的基础理解

    1.JVM -- java virtual machine JVM就是我们常说的java虚拟机,它是整个java实现跨平台的 最核心的部分,所有的java程序会首先被编译为.class的类文件,这种类 ...

  9. 关于Sql注入的那些事

    登陆注册应该是每一个网站的必做的业务,但是在选择使用Django中的ORM还是说执行原生的Sql语句不同的人应该会有不同的建议,有经验的开发人员都喜欢原生的sql语句,因为相对于ORM来说,执行效率高 ...

  10. es6精华

    函数: ES6 允许为函数的参数设置默认值,即直接写在参数定义的后面.function log(x, y = 'World') { console.log(x, y); } log('Hello') ...