1028 List Sorting (25 分)

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
#include<bits/stdc++.h>
using namespace std;#define e exp(1)
#define pi acos(-1)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define ll long long
#define ull unsigned long long
#define mem(a,b) memset(a,b,sizeof(a))
int gcd(int a,int b){return b?gcd(b,a%b):a;}const int maxn=100005;
struct student{string id,name;int grade;
}s[maxn];
int n,c;int cmp1(student a,student b)
{return a.id<b.id;
}
int cmp2(student a,student b)
{if(a.name!=b.name)return a.name<b.name;return a.id<b.id;
}
int cmp3(student a,student b)
{if(a.grade!=b.grade)return a.grade<b.grade;return a.id<b.id;
}
int main()
{ios::sync_with_stdio(false);cin>>n>>c;for(int i=0; i<n; i++){cin>>s[i].id>>s[i].name>>s[i].grade;}if(c==1){sort(s,s+n,cmp1);}else if(c==2){sort(s,s+n,cmp2);}else sort(s,s+n,cmp3);for(int i=0; i<n; i++){cout<<s[i].id<<" "<<s[i].name<<" "<<s[i].grade<<'\n';}return 0;
}

1028 List Sorting相关推荐

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

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

  2. 1028. List Sorting (25)

    这道题目主要是排序,刚开始简单写了一个代码,发现最后一个测试数据.发现超时了,sort排序用的是快排.快排平均是O(NlogN),最坏是O(N*N).输入数据是10^5级的,最坏的情况会超过10^10 ...

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

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

  4. [PAT A1028]List Sorting

    [PAT A1028]List Sorting 题目描述 1028 List Sorting (25 分)Excel can sort records according to any column. ...

  5. PAT日志 1028

    顽强的小白 1028 List Sorting (25 分) Excel can sort records according to any column. Now you are supposed ...

  6. PAT甲级题目翻译+答案 AcWing(排序)

    1012 The Best Rank (25 分) 题意 :给ID和3门成绩,计算其平均分A,输出每位学生最好的排名,A>C>M>E 思路 :如果将所需的若干个元素中使第一个元素为后 ...

  7. 【最新合集】PAT甲级最优题解(题解+解析+代码)

    以下每道题均是笔者多方对比后, 思考整理得到的最优代码,欢迎交流! 共同成长哇.可以和博主比拼一下谁刷的更快~ 欢迎收藏.欢迎来玩儿 PAT题解目录 题号 标题 题解 分类 使用算法 1001 A+B ...

  8. 【晴神宝典刷题路】codeup+pat 题解索引(更新ing

    记录一下每天的成果,看多久能刷完伐 codep pat乙级 pat甲级 c2 c/c++快速入门 <算法笔记>2.2小节--C/C++快速入门->顺序结构 例题1-1-1 按要求输出 ...

  9. PAT甲级训练合集(1-70)

    本章题解跳转 考点 P1001 数字的数组表示和处理 P1002 多项式的数组表示和处理 P1003 深度优先搜素 P1004 深度优先搜素 P1005 哈希表 P1006 P1007 数组子区间求和 ...

最新文章

  1. Java绘制基本图形
  2. 零基础转行学Java到底难不难?
  3. 重新想象 Windows 8 Store Apps (10) - 控件之 ScrollViewer 特性: Chaining, Rail, Inertia, Snap, Zoom...
  4. 网络安全、Web安全、渗透测试之笔经面经总结(二)
  5. Backbone Model——数据模型
  6. OxyPlot.Wpf 图表控件使用备忘
  7. OpenCV学习笔记(三):多通道图像分离、混合算子:split(),merge()
  8. Linux使用sendmail发送邮件
  9. Eclipse 下载源码插件
  10. 用c语言编程点亮7个二极管,单片机c语言编程二极管_单片机c语言编程_单片机c语言编程led...
  11. 美学心得(第一百七十九集) 罗国正
  12. C语言数组总结与反思
  13. 教你巧用万用表测量大值电阻
  14. 一位优秀的学弟,计算机2019保研经历分享(北大信科、清华计算机系)
  15. 单元测试之moles
  16. 比较正确的 iPhone7/7+ 的进入DFU的方法是这样的
  17. c语言中tho什么意思,干货丨与老外聊天常用的英文缩写,速度get
  18. 用git统计代码提交行数
  19. uni-app 页面组件生命周期
  20. mysql的锁机制(读锁,写锁,表锁,行锁,悲观锁,乐观锁,间隙锁)

热门文章

  1. jQuery之简单的表单验证
  2. php 将查询出的数组数据存入redis
  3. [改善Java代码]覆写equals方法必须覆写hashCode方法
  4. InvokeHelper,让跨线程访问/修改主界面控件不再麻烦(转)
  5. Windows10上安装Git 2.10.2详细图解
  6. Python进阶_wxpy学习:常见问题
  7. 改变服务器控件的显示属性,2.6.1 设置Style特性和其他属性
  8. 通过History Trends Unlimited通过统计台式机Edge浏览器Top10网页历史访问量(截止至2021.11.23)
  9. 撒花!斯坦福深度学习最新视频发布,吴恩达主讲!
  10. 优麒麟桌面闪烁_UKUI 桌面环境登陆 Arch Linux