PAT_A1028#List Sorting
Source:
Description:
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
Keys:
- 模拟题
Code:
/*
Data: 2019-07-17 18:40:30
Problem: PAT_A1028#List Sorting
AC: 12:22 题目大意:
排序
输入:
第一行给出,记录数N<=1e5,排序规则C
接下来N行,id,name,grade
C=1,id递增
C=2,name递增+id递增
C=3,grade递增+id递增
*/ #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int M=1e5+,N=;
struct node
{
char name[N];
int id,grade;
}info[M]; bool cmp_name(const node &a, const node &b)
{
return strcmp(a.name,b.name) < ;
} bool cmp_grade(const node &a, const node &b)
{
return a.grade < b.grade;
} bool cmp_id(const node &a, const node &b)
{
return a.id < b.id;
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif int n,c;
scanf("%d%d", &n,&c);
for(int i=; i<n; i++)
scanf("%d %s %d\n", &info[i].id,info[i].name,&info[i].grade);
sort(info,info+n,cmp_id);
if(c==)
sort(info,info+n,cmp_name);
if(c==)
sort(info,info+n,cmp_grade);
for(int i=; i<n; i++)
printf("%06d %s %d\n", info[i].id,info[i].name,info[i].grade); return ;
}
PAT_A1028#List Sorting的更多相关文章
- HDU Cow Sorting (树状数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2838 Cow Sorting Problem Description Sherlock's N (1 ...
- 1306. Sorting Algorithm 2016 12 30
1306. Sorting Algorithm Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description One of the f ...
- 算法:POJ1007 DNA sorting
这题比较简单,重点应该在如何减少循环次数. package practice; import java.io.BufferedInputStream; import java.util.Map; im ...
- U3D sorting layer, sort order, order in layer, layer深入辨析
1,layer是对游戏中所有物体的分类别划分,如UIlayer, waterlayer, 3DModelLayer, smallAssetsLayer, effectLayer等.将不同类的物体划分到 ...
- WebGrid with filtering, paging and sorting 【转】
WebGrid with filtering, paging and sorting by Jose M. Aguilar on April 24, 2012 in Web Development A ...
- ASP.NET MVC WebGrid – Performing true AJAX pagination and sorting 【转】
ASP.NET MVC WebGrid – Performing true AJAX pagination and sorting FEBRUARY 27, 2012 14 COMMENTS WebG ...
- poj 1007:DNA Sorting(水题,字符串逆序数排序)
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 80832 Accepted: 32533 Des ...
- ural 1252. Sorting the Tombstones
1252. Sorting the Tombstones Time limit: 1.0 secondMemory limit: 64 MB There is time to throw stones ...
- CF#335 Sorting Railway Cars
Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
随机推荐
- pandas 使用出现的问题汇总
问题1:<bound method NDFrame.head of 刚开始还以为是自己的数据集有问题,怎么显示不对呢! 解决: 仔细观察,是自己给的输出有问题,data.head什么鬼??? 正 ...
- layer通过父页面调用子页面的方法及属性
引言 在使用layer.js的过程中,需要通过layer.open()以iframe的形式打开特定的页面,同时需要用layer的按钮对打开的页面进行提交及重置操作,但是苦于不知如何在父页面调用子页面的 ...
- 最新版本IntelliJ IDEA 2019.3 (Ultimate Edition) 激活及汉化
附:官网idea下载地址 以下有两种破解方式,推荐方式二: =============================破解方式1==================================== ...
- HBase 热点问题——rowkey散列和预分区设计
热点发生在大量的client直接访问集群的一个或极少数个节点(访问可能是读,写或者其他操作).大量访问会使热点region所在的单个机器超出自身承受能力,引起性能下降甚至region不可用,这也会影响 ...
- CSS 中 transform、animation、transition、translate的区别
在前端页面的开发过程中,经常会碰到这么几个 CSS 属性容易搞混:transform.translate.animation还有transition.下面就针对这几个 CSS 属性做一个对比,辨别这几 ...
- 解决 使用migrations 执行update-database 出现System.InvalidOperationException: 实例失败的问题
好久没有使用Code First的方式来创建模型了 今天重温了一下 但是出现了很多问题 现在总结一下 在我做完初期的操作的之后,使用 update-database -verbose 更新数据库时, ...
- ASE团队项目alpha阶段Frontend组 scrum2 记录
ASE团队项目alpha阶段Frontend组 scrum2 记录 本次会议于11.5日, 11:30在微软北京西二楼13158研讨室,讨论持续15分钟 与会人员:Jingyi Xie, Jiaqi ...
- 矩阵的 Frobenius 范数及其求偏导法则
cr:http://blog.csdn.net/txwh0820/article/details/46392293 一.矩阵的迹求导法则 1. 复杂矩阵问题求导方法:可以从小到大,从scalar到 ...
- HTML事件处理程序---内联onclick事件
HTML事件处理程序绑定方法: <input type="button" value="click me" onclick="show(this ...
- vue搭建vue-cli脚手架项目
一.Node.js 1.介绍 Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine.Node.js是一个基于Ch ...