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 ...
随机推荐
- JS-日期和时间
# 格式化日期和时间 扩展 Date: Date.prototype.format = function(format){ var o = { "M+" : this.getMon ...
- 本地安装了flash,前台浏览器还显示需要安装flash?是因为版本需要对应
NPAPI:适用于FireFox(火狐).Safari(苹果).Opera (欧朋,12.17版以下) PPAPI:适用于Chromium浏览器.Opera (欧朋,15.00版以上) ActiveX ...
- Java学习之构造函数
构造函数特点: 函数名和类名相同 没有返回值(不用定义返回值类型)作用: 对象初始化注意: 如果类没有定义构造函数时,系统会默认定义一个无参的构造函数 如果定义了构造函数,系统不会定义构造函 ...
- JAVA学习之面向对象
面向对象是相对面向过程而言面向过程:强调的是功能行为面向对象:将功能封装进对象,强调具备了功能的对象 不论面向对象还是面向过程都是一种开发思想而已.举一个例子来理解面向对象和面向过程把大象装进冰箱分三 ...
- 【lua学习笔记】——环境配置
1 开发平台 windows7 64位 2 下载链接 http://www.lua.org/download.html 3 安装完成-环境配置 4 运行 WIN+R 运行 cmd 运行lua,显示配 ...
- 2019杭电多校第六场hdu6638 Snowy Smile(线段树+枚举)
Snowy Smile 题目传送门 解题思路 先把y离散化,然后把点按照x的大小进行排序,我们枚举每一种x作为上边界,然后再枚举其对应的每一种下边界.按照这种顺序插入点,这是一个压维的操作,即在线段树 ...
- Rust <3>:控制流
if.loop.for.while: fn main() { if 3 > 4 { println!{">"}; } else { println!{"< ...
- 《Hadoop学习之路》学习实践
(实践机器:blog-bench) 本文用作博文<Hadoop学习之路>实践过程中遇到的问题记录. 本文所学习的博文为博主“扎心了,老铁” 博文记录.参考链接https://www.cnb ...
- linux下samba共享服务器搭建详解
这两天业务需求搭了一台服务器.要求samba共享文件. 葡萄美酒月光杯的前戏就省了,我们直接上干货. 1.yum方式安装samba yum -y install samba 2.将/etc/sam ...
- 在Ubuntu下安装deb包需要使用dpkg命令
Dpkg 的普通用法: 1.sudo dpkg -i <package.deb> 安装一个 Debian 软件包,如你手动下载的文件. 2.sudo dpkg -c <package ...