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 (≤) 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
自定义结构体排序
 #include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
struct node
{
string str1,str2;
int str3;
}a[];
int cmp1(node x,node y)
{
return x.str1<y.str1;
}
int cmp2(node x,node y)
{
if(x.str2==y.str2) return x.str1<y.str1;
return x.str2<y.str2;
}
int cmp3(node x,node y)
{
if(x.str3==y.str3) return x.str1<y.str1;
return x.str3<y.str3;
}
int main()
{
int n,m;
while(cin>>n>>m){
for(int i=;i<n;i++){
cin>>a[i].str1>>a[i].str2>>a[i].str3;
}
if(m==){
sort(a,a+n,cmp1);
}else if(m==){
sort(a,a+n,cmp2);
}else if(m==){
sort(a,a+n,cmp3);
}
for(int i=;i<n;i++){
cout<<a[i].str1<<" "<<a[i].str2<<" "<<a[i].str3<<endl;
}
}
return ;
}

PAT (Advanced Level) Practice 1028 List Sorting (25 分) (自定义排序)的更多相关文章

  1. PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...

  2. PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...

  3. PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642 题目描述: Being unique is so important to peo ...

  4. PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642 题目描述: A reversible prime in any n ...

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

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

  6. PAT (Advanced Level) 1052. Linked List Sorting (25)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

  7. PAT (Advanced Level) Practice 1003 Emergency 分数 25 迪杰斯特拉算法(dijkstra)

    As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...

  8. PAT (Advanced Level) Practice 1120 Friend Numbers (20 分) (set)

    Two integers are called "friend numbers" if they share the same sum of their digits, and t ...

  9. PAT (Advanced Level) Practice 1152 Google Recruitment (20 分)

    In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the p ...

随机推荐

  1. 2020-02-19Linux学习日记,第一天

    今天是2020-02-19第一次写博客.每天更新学习Linux的一些笔记. 主要是为了方便日后自己复习,也是为了督促自己学习.记录自己的学习轨迹! -------------------------- ...

  2. RTEMS进程同步机制

    互斥量 好像没有互斥量,信号量接收那儿有个图,互斥量似乎术语一类特殊的信号量. 信号量 12. Semaphore Manager 12.1. Introduction The semaphore m ...

  3. helm 错误the server has asked for the client to provide credentials

    一.造成错误的原因 不小心把helm的RBAC权限文件删除了.虽然重新apply了RBAC配置,但是已经无法使用helm install了. 二.解决方法 把运行的tiller的pod干掉,让他自动重 ...

  4. centos7.5下yum安装php-5.6.40(LNMP环境)

    cd /etc/yum.repos.d/ yum -y install epel-release #<===安装centos7下php5.6的epel和remi源 rpm -ivh http:/ ...

  5. [CSS]三大特性之一继承性、层叠性、优先级

    <style> div { color: red; font-size: 30px; {#background: #0066ff;#} } </style> <!-- 1 ...

  6. MySQL全文索引、联合索引、like查询、json查询速度大比拼

    目录 查询背景 一.like查询 二.json函数查询 三.联合索引查询 四.全文索引查询 结论 查询背景 有一个表tmp_test_course大概有10万条记录,然后有个json字段叫outlin ...

  7. C语言基础二 练习

    指出正确标识符 命名 l 只能由26个英文字母的大小写.10个阿拉伯数字0~9.下划线_组成 l 严格区分大小写,比如test和Test是2个不同的标识符 l 不能以数字开头 l 不可以使用关键字作为 ...

  8. 戏说前端之CSS编码规范

    前言 项目启动时 css 应该注意哪些问题 文件名规范 文件名建议用小写字母加中横线的方式.为什么呢?因为这样可读性比较强,看起来比较清爽,像链接也是用这样的方式,例如 // 地址: github的地 ...

  9. symfonos2

    0x01 进入网页 啥也没有 0x02 目录爆破 啥也没有 0x03 端口扫描 知识盲区: ProFTPD 1.3.5 用ProFTPD服务权限执行复制命令,默认在'nobody'用户的特权下运行.通 ...

  10. 编译Qualcomm的Hexagon exampls错误

    在下载了Qualcomm的Hexagon SDK 351版本之后,想跑里面的examples,然后参照文档的说,比如在examples/common/sobel3x3_v60目录下面,先执行了SDK根 ...