#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. PHP中SimpleXMLElement对象字符编码

    最近在使用SimpleXMLElement来生成和解析XML. 由于我们使用PHP开发的这边使用UTF-8编码,而对方使用GBK编码,因此就遇到了中文字符编码问题. 后来发现,XML内部的编码与其头 ...

  2. 2016级算法第四次上机-B ModricWang的序列问题

    1019 ModricWang的序列问题 思路 此题题意非常清晰,给定一个序列,求出最长上升子序列的长度.从数据规模来看,需要\(O(nlogn)\) 的算法. \(O(nlongn)\) 求最长上升 ...

  3. 977 AlvinZH过生日(背包DP大作战S)

    977 AlvinZH过生日 思路 难题.逆推DP. 要明确dp的状态只与是否有选择权有关,而与选择权在谁手里无关.因为不论选择权在谁手里,那个人都会尽可能的获得最大的蛋糕重量. dp[i]表示分配到 ...

  4. (STM32F4) SysTick理解使用

    關於Cortex System Timer (Systick) 網上隨便google就可以找到許多相關範例. 他就是ARM提供的一個24-bit的下數(count-down)計時器我看大部分應用都是提 ...

  5. 虚拟机上使用 opecnv 读取USB摄像头无法显示

    使用opecv读取USB摄像头时候,无法显示图像. 设置 首先查看虚拟机Ubuntu检测摄像头是否已正常插入: ls /dev/video* 结果为: 设置虚拟机USB属性: USB的兼容性设置为US ...

  6. 【笔记】Django的视图

    [笔记]Django的视图 Python Django  Django的View(视图) 一个视图函数(类),简称视图,是一个简单的Python 函数(类),它接受Web请求并且返回Web响应. 响应 ...

  7. [转] Java 命令行交互-JCommander

    [From] https://github.com/Sayi/sayi.github.com/issues/32 我喜欢简单,什么是简单?正如若干字符组成的命令行. 有时候我们用Java开发了一个小工 ...

  8. JavaScript 流程控制器

    已知有流程step1.step2.step3.step4.step5 , 如何控制输出下面过程 例如: 1:step1.step2.step3.step2.step3.step4.step5 2:st ...

  9. Oracle SQL Developer 查询时间格式

    工具->首选项->数据库->NLS->日期格式: DD-MON-RR 修改为: YYYY-MM-DD HH24:MI:SS

  10. zipimport.ZipImportError: can't find module 'encodings'

    环境说明:windows 7.python 3.7.0.pyinstaller 3.1. 解决方案:升级pyinstaller 到 3.4.