博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT(A) 1028. List Sorting (25)
阅读量:4681 次
发布时间:2019-06-09

本文共 1807 字,大约阅读时间需要 6 分钟。

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

Input

Each input file contains one test case. For each case, the first line contains two integers N (<=100000) 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

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 1000007 James 85000010 Amy 90000001 Zoe 60

Sample Output 1

000001 Zoe 60000007 James 85000010 Amy 90

Sample Input 2

4 2000007 James 85000010 Amy 90000001 Zoe 60000002 James 98

Sample Output 2

000010 Amy 90000002 James 98000007 James 85000001 Zoe 60

Sample Input 3

4 3000007 James 85000010 Amy 90000001 Zoe 60000002 James 90

Sample Output 3

000001 Zoe 60000007 James 85000002 James 90000010 Amy 90
#include 
#include
#include
using namespace std;const int maxn=100005;struct Node{ int id; //准考证号 char name[10]; //姓名 int score; //分数}stu[maxn];//划重点:按三种排序规则写三个cmp(), 根据读入C的不同选择不同的排序函数//C==1: 按准考证从小到大排序bool cmp1(Node a, Node b){ return a.id

 

转载于:https://www.cnblogs.com/claremore/p/6549557.html

你可能感兴趣的文章
简单FTP服务器搭建
查看>>
关于Sublime Text 3搭建Java环境的补充
查看>>
【FFMPEG】Ubuntu上安装FFMPEG
查看>>
【QT开发】信号转发器QSignalMapper的使用
查看>>
关于VS2010工程各种路径注意事项汇总
查看>>
Codeforces 732F. Tourist Reform (Tarjan缩点)
查看>>
JavaScript设计模式
查看>>
C++程序设计之提高效率
查看>>
set unused的用法(ORACLE删除字段)
查看>>
决策树算法
查看>>
hdu 1198 Farm Irrigation
查看>>
80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
查看>>
三角洲调平说明
查看>>
线程和进程(Java)
查看>>
PMP CMM
查看>>
day03 bs4解析库之遍历文档树
查看>>
Linux下通过ssh访问另一台内网服务器
查看>>
antd在webpack里面的配置
查看>>
redis 适用场景、缓存选择、java实现
查看>>
国际化问题简述
查看>>