题干:

Excel can sort records according to any column. Now you are supposed to imitate this function.

Input Specification:

Each input file contains one test case. For each case, the first line contains two integers N (≤10​5​​) and C, where N is the number of records and C is the column that you are supposed to sort the records with. Then N lines follow, each contains a record of a student. A student's record consists of his or her distinct ID (a 6-digit number), name (a string with no more than 8 characters without space), and grade (an integer between 0 and 100, inclusive).

Output Specification:

For each test case, output the sorting result in N lines. That is, if C = 1 then the records must be sorted in increasing order according to ID's; if C = 2 then the records must be sorted in non-decreasing order according to names; and if C = 3 then the records must be sorted in non-decreasing order according to grades. If there are several students who have the same name or grade, they must be sorted according to their ID's in increasing order.

Sample Input 1:

3 1
000007 James 85
000010 Amy 90
000001 Zoe 60

Sample Output 1:

000001 Zoe 60
000007 James 85
000010 Amy 90

Sample Input 2:

4 2
000007 James 85
000010 Amy 90
000001 Zoe 60
000002 James 98

Sample Output 2:

000010 Amy 90
000002 James 98
000007 James 85
000001 Zoe 60

Sample Input 3:

4 3
000007 James 85
000010 Amy 90
000001 Zoe 60
000002 James 90

Sample Output 3:

000001 Zoe 60
000007 James 85
000002 James 90
000010 Amy 90

题目大意:

给定n个学生的学号,姓名,分数。让你按照一定的要求排序

解题报告:

按照题意模拟。注意sort中这种ifelse的,第二个别忘写return啊。。不然肯定就错了。然后,用cin会T。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
struct Node {int id;string name;int grd;
} R[MAX];
int n,op;
bool cmp1(Node a,Node b) {return a.id < b.id;
}
bool cmp2(Node a,Node b) {if(a.name != b.name) return a.name < b.name;else return a.id < b.id;
}
bool cmp3(Node a,Node b) {if(a.grd != b.grd) return a.grd < b.grd;else return a.id < b.id;
}
char s[MAX];
int main()
{cin>>n>>op;for(int i = 1; i<=n; i++) {scanf("%d%s%d",&R[i].id,s,&R[i].grd);R[i].name = s;}if(op == 1) sort(R+1,R+n+1,cmp1);if(op == 2) sort(R+1,R+n+1,cmp2);if(op == 3) sort(R+1,R+n+1,cmp3);for(int i = 1; i<=n; i++) {printf("%.6d %s %d\n",R[i].id,R[i].name.c_str(),R[i].grd);}return 0 ;
}

【PAT甲级 - 1028】List Sorting (25分)(模拟,排序)相关推荐

  1. PAT甲级1028 List Sorting:[C++题解]排序,cin和cout会超时

    文章目录 题目分析 题目链接 题目分析 用结构体来存,写三个排序函数. 本题需要注意的点是: 用cin来读会超时,所以用C语言的scanf来读.这样的话,就不能使用string,而是使用char数组. ...

  2. 【简洁代码】1028 List Sorting (25 分)_26行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Excel can sort records according to any column. Now you are suppo ...

  3. 【PAT - 甲级1003】Emergency (25分)(Dijkstra,最短路条数,双权值最短路)

    题干: As an emergency rescue team leader of a city, you are given a special map of your country. The m ...

  4. 【PAT甲级A1003 】Emergency (25分)(c++)

    1003 Emergency (25分) 作者:CHEN, Yue 单位:浙江大学 代码长度限制:16 KB 时间限制:400 ms 内存限制:64 MB As an emergency rescue ...

  5. 19年春季第二题 PAT甲级 1157 Anniversary(25 分)

    英文题目 Zhejiang University is about to celebrate her 122th anniversary in 2019. To prepare for the cel ...

  6. 19年冬季第二题 PAT甲级 1165 Block Reversing (25分) 跟1133类似的题目

    题目 Given a singly linked list L. Let us consider every K nodes as a block (if there are less than K ...

  7. 【PAT - 甲级1010】Radix (25分)(二分,进制转化)

    题干: Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? Th ...

  8. PAT甲级1139 First Contact (30 分):[C++题解] 图论、暴力枚举两个点、hash映射

    文章目录 题目分析 题目链接 题目分析 来源:acwing 题目分析: 图论模拟题. 给定暗恋的两个人A 和B,需要寻找一对C 和D ,满足:A和C是朋友,C和D是朋友,D和B是朋友.而且A.C同性别 ...

  9. PAT甲级1004 Counting Leaves (30分):[C++题解]树、邻接表存储树、dfs遍历树

    文章目录 题目分析 题目链接 题目分析 题意重述:一棵树,求每一层的叶子节点数目. 分析 构造树,使用邻接表来存(相当于存储有向图). 需要一个头结点数组h[N],然后每个头节点往外形成一个单链表e[ ...

  10. PAT乙级 1110 区块反转 (25 分) C++

    1110 区块反转 (25 分) 给定一个单链表 L,我们将每 K 个结点看成一个区块(链表最后若不足 K 个结点,也看成一个区块),请编写程序将 L 中所有区块的链接反转.例如:给定 L 为 1→2 ...

最新文章

  1. elasticsearch资源汇总
  2. Django 数据库建表的时候 No migrations to apply原因出现和解决
  3. Eclipse报错:java.lang.ClassNotFoundException: ContextLoaderListener
  4. BeautifulSoup库用法总结
  5. c 定义结构体时提示应输入声明_C|语法的合理性理解和分析
  6. Java语言速览:StackOverflow
  7. 2021-11-14
  8. Nmap库ICMP主机探测
  9. 吉他音阶训练入门教程——中集(运用方法)
  10. 4.1网络层功能概述
  11. Invalid bound statement (not found): com.java.mapper.UserMapper.queryAll错误解决方案
  12. 微信竟可以查出行轨迹了,预计又一波情侣要分手?
  13. SAP CO-PC物料标准价格更改方案
  14. 经典神经网络论文超详细解读(八)——ResNeXt学习笔记(翻译+精读+代码复现)
  15. BDLS协议重磅发布 — Sperax启动Bug Bounty计划
  16. JS下载文件|无刷新下载文件
  17. Django实现单点登录(SSO)
  18. 什么是内部类,以及内部类的特点
  19. java实现“两数之和”
  20. 中国城市竞争力排名出炉

热门文章

  1. Pydiction : VIM上的PYTHON代码自动补全插件
  2. 在CentOS下源码安装 Xen并搭建Windows虚拟机
  3. 【数据结构与算法】【算法思想】分治算法
  4. android studio 无法输入中文,Android Studio 升级到3.0后输入法中文状态下无法选词的终极解决方案...
  5. java mtom_java-axis1.4客户端使用Mtom发送文件
  6. aes密文长度_RSA加密密文可变(一句话说明)
  7. 2021数学建模C题思路数据挖掘
  8. VxWorks动态加载.out文件
  9. 学安全工程用不用计算机,上重点大学的末流专业,不如上普通大学的重点专业,你赞成吗?...
  10. python中如何标识语句块_如何用python在一个块中编写多个try语句?