【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 ...
随机推荐
- Linq Group by获取数量和数据
主表: public partial class Activity { [Key] public int pkActivity { get; set; } public int fkEmployee ...
- [Fiddler学习] - Mock的简单实现原理及方法
最近在研究Fidder抓包并做一点测试工作,下面介绍一下Fiddler的实现原理: 简单来说从clent,server端发出来的请求,都需要通过Fiddler进行代理走一遍.如果有任何请求需要做修改, ...
- blg_统考,打印准考证 网页代码!
<html xmlns="http://www.w3.org/1999/xhtml"><head> <title>打印准考证</title ...
- 前端开发CSS清除浮动的方法有哪些?
在前端开发过程中,非IE浏览器下,当容器的高度自动,并且容器内容中有浮动元素(float为left或right),此时如果容器的高度不能自适应内容的高度,从而使得内容溢出破坏整体布局,这种现象叫做浮动 ...
- Springmvc-crud-05(路径错误)
错误: 原因:Tomcat8之后的一些高版本,使用restful风格访问然后转发到jsp页面,进行业务操作时会报路径错误 解决方案①:修改jsp页面中的page指令isErrorPage=" ...
- Cosmetic Airless Bottles To Meet Practical Requirements
Today, people use cosmetic bottles, many of which are in cosmetic airless bottles. We can use them, ...
- 吴裕雄 python 神经网络——TensorFlow 训练过程的可视化 TensorBoard的应用
#训练过程的可视化 ,TensorBoard的应用 #导入模块并下载数据集 import tensorflow as tf from tensorflow.examples.tutorials.mni ...
- 【MySQL】完整性约束
" 目录 not null default unique 单列唯一 联合唯一 primary key 单列主键 复合主键 auto_increment 步长与偏移量 foreign key ...
- IDEA启动报错-java.net.BindException: Address already in use: bind
启动IDEA报错日志如下: Internal error. Please refer to http://jb.gg/ide/critical-startup-errors java.net.Bind ...
- Python - 八大排序算法
1.序言 本文使用Python实现了一些常用的排序方法.文章结构如下: 1.直接插入排序 2.希尔排序 3.冒泡排序 4.快速排序 5.简单选择排序 6.堆排序 7.归并排序 8.基数排序 上述所有的 ...