#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. python中package机制的两种实现方式

    当执行import module时,解释器会根据下面的搜索路径,搜索module1.py文件. 1) 当前工作目录 2) PYTHONPATH中的目录 3) Python安装目录 (/usr/loca ...

  2. centos yum安装php5.6.19 remi源按照

    yum安装php5.6 多版本php共存 remi安装方法 http://www.servermom.org/how-to-enable-remi-repo-on-centos-7-6-and-5/2 ...

  3. P1642 规划 01分数规划+树形DP

    $ \color{#0066ff}{ 题目描述 }$ 某地方有N个工厂,有N-1条路连接它们,且它们两两都可达.每个工厂都有一个产量值和一个污染值.现在工厂要进行规划,拆除其中的M个工厂,使得剩下的工 ...

  4. css3 -webkit-filter

    -webkit-filter是css3的一个属性,Webkit率先支持了这几个功能,感觉效果很不错.下面咱们就学习一下filter这个属性吧. 现在规范中支持的效果有: grayscale 灰度   ...

  5. 使用bootstrap-table插件

    1.用户提交信息过滤表格内容: a.设置表格查询参数,并在用户提交按钮时候更新表格 <form id="current_table" class="form-inl ...

  6. pydicom读取dicom文件报错

    之前采用pydicom读取dicom文件一切都很正常,不过最近读取一批数据的时候,会报错 读取代码 file = pydicom.read_file(filepath) data = file.pix ...

  7. idea使用时,部分jdk的jar包(tool.jar com.sun.javadoc) 无法引入-gradle处理方案

    gradle 增加配置 def jdkHome = System.getenv("JAVA_HOME") dependencies { compile files("$j ...

  8. mysql 查询json字段 json_extract (mysql 5.7及以上)

    找第一层: SELECT * FROM tourists WHERE json_data->'$.weixinOpenId' = '299485886686868' 或者 SELECT * FR ...

  9. nodejs之socket.io 聊天实现

    写在前面:最近很火的“996”话题,可谓是引起一片热议,马老师说:能够996应该是幸运的,996是对奋斗者的一种机遇(记得不是很清楚).996缺少的是自己的空闲时间了,当我是空闲的时候偶尔996挺好的 ...

  10. $bzoj1027-JSOI2007$ 合金 计算几何 最小环

    题面描述 某公司加工一种由铁.铝.锡组成的合金.他们的工作很简单.首先进口一些铁铝锡合金原材料,不同种类的原材料中铁铝锡的比重不同.然后,将每种原材料取出一定量,经过融解.混合,得到新的合金.新的合金 ...