PAT 甲级 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 分)(排序,简单题)的更多相关文章
- PAT 甲级 1028. List Sorting (25) 【结构体排序】
题目链接 https://www.patest.cn/contests/pat-a-practise/1028 思路 就按照 它的三种方式 设计 comp 函数 然后快排就好了 但是 如果用 c++ ...
- PAT 甲级 1042 Shuffling Machine (20 分)(简单题)
1042 Shuffling Machine (20 分) Shuffling is a procedure used to randomize a deck of playing cards. ...
- PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)
1016 Phone Bills (25 分) A long-distance telephone company charges its customers by the following r ...
- PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)
1146 Topological Order (25 分) This is a problem given in the Graduate Entrance Exam in 2018: Which ...
- 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 ...
- PAT 甲级 1037 Magic Coupon (25 分) (较简单,贪心)
1037 Magic Coupon (25 分) The magic shop in Mars is offering some magic coupons. Each coupon has an ...
- PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习
1020 Tree Traversals (25分) Suppose that all the keys in a binary tree are distinct positive intege ...
- PAT 甲级 1071 Speech Patterns (25 分)(map)
1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For ex ...
- 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 ...
随机推荐
- 一个页面,WEB全功能
当鼠标在页面上往下滑动的时候,页面也一直向下,标签也顺带着全部向下滑动 以前浏览页面,主要是在PC上进行浏览,一个页面不适于太长,需要用户向下拖动: 当时的设计是,点击标签,点击不同的标签,跳转到不同 ...
- ubuntu---记录. opencv3.4.7
一.下载 https://github.com/opencv/opencv/archive/3.4.7.zip wget -c https://github.com/opencv/opencv/arc ...
- YOLO---多个版本的简单认识
YOLO---多个版本的简单认识 YOLOv3 有好几个经典版本了:一.YOLOv3 (Darknet)官网 @ https://github.com/pjreddie/darknet二.YOLOv3 ...
- Til the Cows Come Home(Dijkstra)
Dijkstra (迪杰斯特拉)最短路算法,算是模板 POJ - 2387 #include<iostream> #include<algorithm> #include< ...
- Selenium(四)使用xpath定位元素
1.什么是xpath: 2.xpath的节点类型 3.xpath的表达式 4.开始定位 浏览器打开本地文件: (python3.7的打开语法) 查找根节点: (绝对路径)查找子节点: 查找type ...
- asp.net mvc(模式)和三层架构(BLL、DAL、Model)的联系与区别 转载自:http://blog.csdn.net/luoyeyu1989/article/details/8275866
首先,MVC和三层架构,是不一样的. 三层架构中,DAL(数据访问层).BLL(业务逻辑层).WEB层各司其职,意在职责分离. MVC是 Model-View-Controller,严格说这三个加起来 ...
- [Google Guava] 7-原生类型
原文链接 译文链接 译者:沈义扬,校对:丁一 概述 Java的原生类型就是指基本类型:byte.short.int.long.float.double.char和boolean. 在从Guava查找原 ...
- CF796C Bank Hacking 细节
思路十分简单,答案只有 3 种可能,但是有一些细节需要额外注意一下. code: #include <bits/stdc++.h> #define N 300002 #define set ...
- python基础-垃圾回收机制
垃圾回收 Python中的垃圾回收是以引用计数为主,分代收集为辅.引用计数的缺陷是循环引用的问题. 引用计数 原理:当一个对象的引用被创建或者复制时,对象的引用计数加1:当一个对象的引用被销毁时,对象 ...
- JVM备忘点(1.8以前)
1.内存结构 左边两个线程共享,右边三个线程私有. 方法区:.class文件的类信息.常量.static变量.即时编译器编译后的代码(动态代理).HotSpot将方法区称为永久代 堆:分为新生代和老年 ...