题意:

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

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
typedef struct student{
string id,name;
int grade;
};
student s[];
bool cmp(student a,student b){
return a.id<b.id;
}
bool cmp2(student a,student b){
if(a.name!=b.name)
return a.name<b.name;
return a.id<b.id;
}
bool cmp3(student a,student b){
if(a.grade!=b.grade)
return a.grade<b.grade;
return a.id<b.id;
}
int main(){
int n,c;
cin>>n>>c;
for(int i=;i<=n;++i)
cin>>s[i].id>>s[i].name>>s[i].grade;
if(c==)
sort(s+,s++n,cmp);
else if(c==)
sort(s+,s++n,cmp2);
else if(c==)
sort(s+,s++n,cmp3);
for(int i=;i<=n;++i){
cout<<s[i].id<<" "<<s[i].name<<" "<<s[i].grade;
cout<<((i==n)?"":"\n");
}
return ;
}

【PAT甲级】1028 List Sorting (25 分)的更多相关文章

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

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

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

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

  3. PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习

    1020 Tree Traversals (25分)   Suppose that all the keys in a binary tree are distinct positive intege ...

  4. PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)

    1146 Topological Order (25 分)   This is a problem given in the Graduate Entrance Exam in 2018: Which ...

  5. PAT 甲级 1071 Speech Patterns (25 分)(map)

    1071 Speech Patterns (25 分)   People often have a preference among synonyms of the same word. For ex ...

  6. PAT 甲级 1063 Set Similarity (25 分) (新学,set的使用,printf 输出%,要%%)

    1063 Set Similarity (25 分)   Given two sets of integers, the similarity of the sets is defined to be ...

  7. PAT 甲级 1059 Prime Factors (25 分) ((新学)快速质因数分解,注意1=1)

    1059 Prime Factors (25 分)   Given any positive integer N, you are supposed to find all of its prime ...

  8. PAT 甲级 1051 Pop Sequence (25 分)(模拟栈,较简单)

    1051 Pop Sequence (25 分)   Given a stack which can keep M numbers at most. Push N numbers in the ord ...

  9. PAT 甲级 1048 Find Coins (25 分)(较简单,开个数组记录一下即可)

    1048 Find Coins (25 分)   Eva loves to collect coins from all over the universe, including some other ...

  10. PAT 甲级 1037 Magic Coupon (25 分) (较简单,贪心)

    1037 Magic Coupon (25 分)   The magic shop in Mars is offering some magic coupons. Each coupon has an ...

随机推荐

  1. angular iframe 加载失效解决办法已经自适应高度

    <iframe frameborder="0" id="iframe1"></iframe> $('#iframe1').attr('s ...

  2. 基于Aspectj表达式配置的Spring AOP

    AOP(Aspect-Oriented Programming, 面向切面编程):是一种新的方法论, 是对传统OOP(Object-Oriented Programming, 面向对象编程)的补充. ...

  3. mvc 部分页

    在一些复杂的项目中,我们经常会遇到一个页面存在很多模块,存在页面交互或者加载数据过多等问题,这种时候,我们很可能会考虑到通过使用部分页来解决这个问题(ps:当然还有很多的解决方案,在这里只是简单介绍这 ...

  4. inconsistent use of tabs and spaces in indentation

    这个报错就是混用了tab和4个空格造成的,检查代码,要不全部用tab,要不全部用4个空格,或者用idle编辑器校正

  5. Yii2框架 常用函数整合

    1.使用事务添加数据: public function create() { if($this->validate()) { $trans = Yii::$app->db->begi ...

  6. 11,html5为什呢只需要写<!DOCTYPE HTML>

    11,html5为什呢只需要写<!DOCTYPE HTML> html5不基于SGML,不需要对dtd(百科:翻译为文档类型定义,作用是定义xml文档的合法构建模块,成行声明于xml文档中 ...

  7. LVS+Keepalived -----> 效率最高的负载均衡器

    一. 简介  1. 负载均衡的类型  负载均衡可以采用硬件设备(例如常常听见的 F5),也可以采用软件负载 商用硬件负载设备成本通常较高(一台几十万甚至上百万),所以一般 情况下会采用软件负载 软件负 ...

  8. 使用js制作 下拉选择日期列表 (即日期选择器)

    上代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <tit ...

  9. 2.1.FastDFS-单机拆分版-单机版安装配置

    Centos610系列配置 1.什么是FastDFS? FastDFS是一个开源的分布式文件系统,她对文件进行管理,功能包括:文件存储.文件同步.文件访问(文件上传.文件下载)等,解决了大容量存储和负 ...

  10. CSS中 - display: inline-block

    参考 https://stackoverflow.com/questions/9189810/css-display-inline-vs-inline-block An inline-block el ...