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 (≤) 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

思路:

简单,三种排序可能,cmp写一下

AC代码:

#include<bits/stdc++.h>
using namespace std;
struct node
{
string num;
string name;
int score;
}a[];
bool cmp1(node x,node y){
return x.num<y.num;
};
bool cmp2(node x,node y){
if(x.name==y.name){
return x.num<y.num;
}
else return x.name<y.name;
};
bool cmp3(node x,node y){
if(x.score==y.score){
return x.num<y.num;
}
else return x.score<y.score;
};
int main()
{
int n,m;
cin>>n>>m;
for(int i=;i<=n;i++){
cin>>a[i].num>>a[i].name>>a[i].score;
}
if(m==){
sort(a+,a++n,cmp1);
}else if(m==){
sort(a+,a++n,cmp2);
}else{
sort(a+,a++n,cmp3);
}
for(int i=;i<=n;i++){
cout<<a[i].num<<" "<<a[i].name<<" "<<a[i].score<<endl;
}
return ;
}

PAT 甲级 1028 List Sorting (25 分)(排序,简单题)的更多相关文章

  1. PAT 甲级 1028. List Sorting (25) 【结构体排序】

    题目链接 https://www.patest.cn/contests/pat-a-practise/1028 思路 就按照 它的三种方式 设计 comp 函数 然后快排就好了 但是 如果用 c++ ...

  2. PAT 甲级 1042 Shuffling Machine (20 分)(简单题)

    1042 Shuffling Machine (20 分)   Shuffling is a procedure used to randomize a deck of playing cards. ...

  3. PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)

    1016 Phone Bills (25 分)   A long-distance telephone company charges its customers by the following r ...

  4. PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)

    1146 Topological Order (25 分)   This is a problem given in the Graduate Entrance Exam in 2018: Which ...

  5. PAT 甲级 1055 The World's Richest (25 分)(简单题,要用printf和scanf,否则超时,string 的输入输出要注意)

    1055 The World's Richest (25 分)   Forbes magazine publishes every year its list of billionaires base ...

  6. PAT 甲级 1037 Magic Coupon (25 分) (较简单,贪心)

    1037 Magic Coupon (25 分)   The magic shop in Mars is offering some magic coupons. Each coupon has an ...

  7. PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习

    1020 Tree Traversals (25分)   Suppose that all the keys in a binary tree are distinct positive intege ...

  8. PAT 甲级 1071 Speech Patterns (25 分)(map)

    1071 Speech Patterns (25 分)   People often have a preference among synonyms of the same word. For ex ...

  9. PAT 甲级 1063 Set Similarity (25 分) (新学,set的使用,printf 输出%,要%%)

    1063 Set Similarity (25 分)   Given two sets of integers, the similarity of the sets is defined to be ...

随机推荐

  1. Django drf:幂等性

    一.什么叫做幂等性 用户对于同一操作发起的一次请求或者多次请求的结果是一致的,不会因为多次点击而产生了副作用.举个最简单的例子,那就是支付,用户购买商品使用约支付,支付扣款成功,但是返回结果的时候网络 ...

  2. Django drf:认证及组件、token、局部钩子源码分析

    一.drf认证功能 二.token讲解 三.局部钩子源码分析 一.drf认证功能 1.认证简介: 只有认证通过的用户才能访问指定的url地址,比如:查询课程信息,需要登录之后才能查看,没有登录则不能查 ...

  3. linux 服务器常规巡检并生成报表(一)

    背景 最近接到一个需求要求每天巡检各台业务设备,并导出报表,但一想到设备有N台,一台台每天巡检这样的重复劳作实在是太伤神了,因此决定写一个脚本来搞定这件事. 首先,第一个要解决的问题是批量服务器执行命 ...

  4. python基本应用--三元应用

    格式为:result=值1 if 条件 else 值2 如 a,b,c = 1,3,5 d =a if a>b else c 那么d的结果是多少? 其实可以使用if来完全表达 if a>b ...

  5. mybatise 设置全局变量实例

    前言 在平时的工作中有时候是需要在配置文件中配置全局变量的,因为这些东西是不会变的,并且每个mapper都传参的话也显得有点繁琐,还好mybatis本身是支持全局变量的,今天工作中用到了,记录一下. ...

  6. selenium 键盘事件 模拟ctrl+v 然后键盘点击回车键

    #windows下执行 import win32api,win32con,win32clipboard as w #获取剪切板内容 def get_text(): w.OpenClipboard() ...

  7. JavaScript 中call()、 apply()、 bind()改变this指向理解

    最近开发的过程中遇到了this指向问题,首先想到的是call().apply().bind()三个方法,有些时候这三个方法确实是十分重要,现在我们就把他们的使用方法及异同点讲解一下. 1.每个函数都包 ...

  8. HDU 6143 - Killer Names | 2017 Multi-University Training Contest 8

    /* HDU 6143 - Killer Names [ DP ] | 2017 Multi-University Training Contest 8 题意: m个字母组成两个长为n的序列,两序列中 ...

  9. django 内置标签

    1.autoescape 自动转义开关 官网:https://docs.djangoproject.com/en/2.2/ref/templates/builtins/ 作用:将 html 内容解析成 ...

  10. mysql 常见ALTER TABLE操作

    删除列 alter table table-name drop col-name; 增加列(单列) alter table table-name add col-name col-type comme ...