【PAT甲级】1028 List Sorting (25 分)
题意:
输入一个正整数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 分)的更多相关文章
- 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) 【结构体排序】
题目链接 https://www.patest.cn/contests/pat-a-practise/1028 思路 就按照 它的三种方式 设计 comp 函数 然后快排就好了 但是 如果用 c++ ...
- PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习
1020 Tree Traversals (25分) Suppose that all the keys in a binary tree are distinct positive intege ...
- PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)
1146 Topological Order (25 分) This is a problem given in the Graduate Entrance Exam in 2018: Which ...
- PAT 甲级 1071 Speech Patterns (25 分)(map)
1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For ex ...
- 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 ...
- 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 ...
- 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 ...
- PAT 甲级 1048 Find Coins (25 分)(较简单,开个数组记录一下即可)
1048 Find Coins (25 分) Eva loves to collect coins from all over the universe, including some other ...
- PAT 甲级 1037 Magic Coupon (25 分) (较简单,贪心)
1037 Magic Coupon (25 分) The magic shop in Mars is offering some magic coupons. Each coupon has an ...
随机推荐
- python练习:编写一个程序,要求用户输入10个整数,然后输出其中最大的奇数,如果用户没有输入奇数,则输出一个消息进行说明。
python练习:编写一个程序,要求用户输入10个整数,然后输出其中最大的奇数,如果用户没有输入奇数,则输出一个消息进行说明. 重难点:通过input函数输入的行消息为字符串格式,必须转换为整型,否则 ...
- 题解 P4568 【[JLOI2011]飞行路线】
P4568 [JLOI2011]飞行路线 分层图模板题,相似的题还有P4822 [BJWC2012]冻结,P2939 [USACO09FEB]改造路Revamping Trails,其实做惯了也就不难 ...
- C语言与汇编的嵌入式编程:main中模拟函数的调用(两数交换)
编写一个两数交换函数swap,具体代码如下: #include<stdio.h> void swap(int *p1,int *p2) { int temp; temp = *p1; *p ...
- 传奇身上装备升级系列脚本,以及UPGRADEITEMEX 脚本的详细参数解释
UPGRADEITEMEX 脚本的详细参数解释如下: UPGRADEITEMEX 物品位置(0-12) 属性位置(0-14) 成功机率(0-100) 点数机率(0-255) 是否破碎(0,1) 物品位 ...
- 《JavaScript高级程序设计》读书笔记(五)引用类型
内容---使用对象---创建并操作数组---理解基本的JavaScript类型---使用基本类型和基本包装类型 引用类型--引用类型的值(对象)是引用类型的一个实例--在ECMAScript中,引用类 ...
- CAN总线学习笔记
1.CAN总线信息包的格式 问题: 1.CAN总线的初始化要初始化哪些东西? 2.处理器如何与CAN总线之间进行连接? 硬件连接 关于CC2底盘CAN通信的协议格式 备注: 设备地址为01 功能码
- HDU 3081 Marriage Match II (二分+网络流+并查集)
注意 这题需要注意的有几点. 首先板子要快,尽量使用带当前弧优化的dinic,这样跑起来不会超时. 使用弧优化的时候,如果源点设置成0,记得将cur数组从0开始更新,因为有的板子并不是. 其次这题是多 ...
- HDU4280 Island Transport
ISAP求最大流模板 #include<cstdio> #include<cstring> #include<algorithm> #include<iost ...
- Nexus-vPC理论
vPC:virtual Port-channel 1.vPC的作用: • 允许一个设备使用2个上游的设备的端口来实现Port Channel • 消除STP阻止端口的情况 • 提供一个无环 ...
- Python数据分析之Numpy操作大全
从头到尾都是手码的,文中的所有示例也都是在Pycharm中运行过的,自己整理笔记的最大好处在于可以按照自己的思路来构建矿建,等到将来在需要的时候能够以最快的速度看懂并应用=_= 注:为方便表述,本章设 ...