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

分析:就是排序的一道题 要注意不能使用cin和cout 不然会超时
用 cin和 cout写法
 #define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
#include<stdlib.h>
#include<vector>
#include<algorithm> using namespace std;
typedef string s[];
int N, C;
bool compare(const vector<string> &s1,const vector<string> &s2)
{
return (s1[C - ] != s2[C - ]) ? s1[C - ] < s2[C - ] : s1[] < s2[];
}
int main()
{
cin >> N >> C;
vector<vector<string> > T(N);
s str;
for (int i = ; i < N; i++)
{
cin >> str[] >> str[] >> str[];
T[i].push_back(str[]);
T[i].push_back(str[]);
T[i].push_back(str[]);
}
sort(T.begin(), T.end(), compare);
for (auto it : T)
cout << it[] <<" "<< it[]<<" "<< it[] << endl;
}

1028 List Sorting (25 分)的更多相关文章

  1. PAT 甲级 1028 List Sorting (25 分)(排序,简单题)

    1028 List Sorting (25 分)   Excel can sort records according to any column. Now you are supposed to i ...

  2. PAT 1028 List Sorting (25分) 用char[],不要用string

    题目 Excel can sort records according to any column. Now you are supposed to imitate this function. In ...

  3. PAT (Advanced Level) Practice 1028 List Sorting (25 分) (自定义排序)

    Excel can sort records according to any column. Now you are supposed to imitate this function. Input ...

  4. 【PAT甲级】1028 List Sorting (25 分)

    题意: 输入一个正整数N(<=100000)和C(C属于{1,2,3}),接下来输入N行,每行包括学生的六位学号(习惯用string输入,因为可能有前导零),名字和成绩(正整数).输出排序后的信 ...

  5. PAT 甲级 1052 Linked List Sorting (25 分)(数组模拟链表,没注意到不一定所有节点都在链表里)

    1052 Linked List Sorting (25 分)   A linked list consists of a series of structures, which are not ne ...

  6. 【PAT】1028. List Sorting (25)

    题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1028 题目描述: Excel can sort records according to an ...

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

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

  8. 1028. List Sorting (25)

    #include <vector> #include <stdio.h> #include <string.h> #include <algorithm> ...

  9. PAT (Advanced Level) 1028. List Sorting (25)

    时间卡的比较死,用string会超时. #include<cstdio> #include<cstring> #include<cmath> #include< ...

随机推荐

  1. Git使用ssh公钥

    Git使用ssh公钥 一.  何谓公钥 1.很多服务器都是需要认证的,ssh认证是其中的一种.在客户端生成公钥,把生成的公钥添加到服务器,你以后连接服务器就不用每次都输入用户名和密码了. 2.很多gi ...

  2. Canny检测算法与实现

    1.原理 图象边缘就是图像颜色快速变化的位置,对于灰度图像来说,也就是灰度值有明显变化的位置.图像边缘信息主要集中在高频段,图像锐化或检测边缘实质就是高通滤波.数值微分可以求变化率,在图像上离散值求梯 ...

  3. [日志分析]Graylog2进阶 通过正则解析Nginx日志

    之前分享的 [日志分析]Graylog2采集Nginx日志 主动方式 这篇文章介绍了Graylog如何通过Graylog Collector Sidecar来采集nginx日志. 由于日志是未经处理的 ...

  4. 当AI遇上K8S:使用Rancher安装机器学习必备工具JupyterHub

    Jupyter Notebook是用于科学数据分析的利器,JupyterHub可以在服务器环境下为多个用户托管Jupyter运行环境.本文将详细介绍如何使用Rancher安装JupyterHub来为数 ...

  5. [前端开发]Vue父子组件的通信及访问

    父传子 props 子传父 自定义事件emit props传数组 props:['cmovies','cmessage'] props传对象 props:{ //1.类型限制 cmovies:Arra ...

  6. JavaScript零宽字符

    什么是零宽字符 一种不可打印的Unicode字符, 在浏览器等环境不可见, 但是真是存在, 获取字符串长度时也会占位置, 表示某一种控制功能的字符. 常见的零宽字符有哪些 零宽空格(zero-widt ...

  7. Requests库发送post请求,传入接口参数后报JSON parse error

    报错信息: {"timestamp":"2020-01-08T14:42:40.894+0000","status":400,"e ...

  8. Splunk 基本使用

    Splunk 作为大数据搜索处理软件,作为行业的翘楚,绝对值得探索和学习,Splunk能实时对任何应用程序.服务器或者网络设备的数据和数据源进行搜索和索引,包括任何位置的日志.配置文件.信息.陷阱和预 ...

  9. 洛谷2212Watering the Fields S 最小生成树

    题目链接:https://www.luogu.com.cn/problem/P2212 几乎是Kruskal裸题,但是建n*(n-1)条边给我T了俩点,后来我发现只要C(n,2)条边就可以,因为假设( ...

  10. hdu2612 又是迷宫系列

    题目链接:http://icpc.njust.edu.cn/Problem/Hdu/2612/ 题意:有两个人在地图上不同的位置,地图上由若干个餐厅,求两人能同时到达一个餐厅所用最少的总时间. 代码如 ...