Source:

PAT A1028 List Sorting (25 分)

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的更多相关文章

  1. HDU Cow Sorting (树状数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2838 Cow Sorting Problem Description Sherlock's N (1  ...

  2. 1306. Sorting Algorithm 2016 12 30

    1306. Sorting Algorithm Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description One of the f ...

  3. 算法:POJ1007 DNA sorting

    这题比较简单,重点应该在如何减少循环次数. package practice; import java.io.BufferedInputStream; import java.util.Map; im ...

  4. U3D sorting layer, sort order, order in layer, layer深入辨析

    1,layer是对游戏中所有物体的分类别划分,如UIlayer, waterlayer, 3DModelLayer, smallAssetsLayer, effectLayer等.将不同类的物体划分到 ...

  5. WebGrid with filtering, paging and sorting 【转】

    WebGrid with filtering, paging and sorting by Jose M. Aguilar on April 24, 2012 in Web Development A ...

  6. 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 ...

  7. poj 1007:DNA Sorting(水题,字符串逆序数排序)

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 80832   Accepted: 32533 Des ...

  8. ural 1252. Sorting the Tombstones

    1252. Sorting the Tombstones Time limit: 1.0 secondMemory limit: 64 MB There is time to throw stones ...

  9. CF#335 Sorting Railway Cars

    Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

随机推荐

  1. Java Freemarker生成word

    Java Freemarker生成word freeMaker 简介: FreeMarker是一款模板引擎: 即一种基于模板和要改变的数据, 并用来生成输出文本(HTML网页.电子邮件.配置文件.源代 ...

  2. Area--->AreaRegister.RegisterAllArea()与Area区域的解析

    文章引导 MVC路由解析---IgnoreRoute MVC路由解析---MapRoute MVC路由解析---UrlRoutingModule Area的使用 Area--->AreaRegi ...

  3. VisualStudio下std::string的内存布局

    主要成员 union _Bxty { // storage for small buffer or pointer to larger one _Elem _Buf[_BUF_SIZE]; _Elem ...

  4. linux 杂七杂八

    一."init"是内核启动的第一个用户空间程序(PID=1),也是所有用户态进程的"大总管":所有内核态进程的大总管是PID=2的[kthreadd]: 二.v ...

  5. 关系型数据的分布式处理系统:Cobar

    Cobar简介 Cobar是关系型数据的分布式处理系统,它可以在分布式的环境下像传统数据库一样为您提供海量数据服务. Github:https://github.com/alibaba/cobar 整 ...

  6. 案例-2D会旋转的盒子(rotate), 会缩放的盒子(scale),动画(animation)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. Mysql中(@i:=@i+1)的作用

    Oracle中有一个伪列rownum,可以在生成查询结果表的时候生成一组递增的序列号.MySQL中没有这个伪列,但是有时候要用,可以用如下方法模拟生成一列自增序号. (1)sql示例:select ( ...

  8. 2018-2-13-win10-uwp-魔力鬼畜

    title author date CreateTime categories win10 uwp 魔力鬼畜 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17: ...

  9. day05 python字典

    day05 python   一.字典     1.dict 用{}表示, 存放的是: key:value    (开发的都知道的是键值对数据,这样说)         key: 关键字不能重复, 不 ...

  10. eclipse中server location为灰色,不能修改

    当自己用eclipse写好了web项目后,也同时配置了服务器(tomcat6), 上面部署完毕后,直接访问http://localhost:8080 发现是 无法访问的,这是因为,Servers这里的 ...