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. JVM03——四种垃圾回收算法,你都了解了哪几种

    在之前的文章中,已经为各位带来了JVM的内存结构与堆内存的相关介绍,今天将为为各位详解JVM垃圾回收与算法.关注我的公众号「Java面典」了解更多 Java 相关知识点. 如何确定垃圾 想要回收垃圾, ...

  2. 【.net core】电商平台升级之微服务架构应用实战

    一.前言 这篇文章本来是继续分享IdentityServer4 的相关文章,由于之前有博友问我关于微服务相关的问题,我就先跳过IdentityServer4的分享,进行微服务相关的技术学习和分享.微服 ...

  3. Python基础篇(四)_组合数据类型的基本概念

    Python基础篇——组合数据类型的基本概念 集合类型:元素的集合,元素之间无序 序列类型:是一个元素向量,元素之间存在先后关系,通过序号进行访问,没有排他性,具体包括字符串类型.元组类型.列表类型 ...

  4. 后端程序员不得不会的 Nginx 转发匹配规则

    整理了一些Java方面的架构.面试资料(微服务.集群.分布式.中间件等),有需要的小伙伴可以关注公众号[程序员内点事],无套路自行领取 一口气说出 9种 分布式ID生成方式,面试官有点懵了 面试总被问 ...

  5. C# 基础知识系列- 2 字符串

    String的常见方法 String 变量的声明方式 C#中字符串常见的声明有两种: 直接使用字面值 即String s = "12321"; 使用构造器,即String s = ...

  6. Journal of Proteome Research | “Differential Visual Proteomics”: Enabling the Proteome-Wide Comparison of Protein Structures of Single-Cells(“差异视觉蛋白质组学”:实现单细胞中蛋白质结构的组学比较)(解读人:李思奇)

    期刊名:Journal of Proteome Research 发表时间:(2019年9月) IF:3.78 (2018) 单位:巴塞尔大学,瑞士 物种:人细胞系 技术:冷冻电子显微镜(Cryo-E ...

  7. hdu2838 cow sorting用树状数组求逆序对

    题目链接:http://icpc.njust.edu.cn/Problem/Hdu/2838/ 题目解法:题目给出一个1-n的排列,操作只有一种:交换相邻的元素,代价是两个元素之和,问将该序列变成升序 ...

  8. 201771010111-李瑞红 实验一 软件工程准备-<构建之法-现代软件工程-基础认识和理解>

    |||||||| | :--

  9. 【i春秋 综合渗透训练】渗透测试笔记

    网站是齐博CMS V7.0    1.要求获得管理员密码:   利用齐博CMS V7.0  SQL爆破注入漏洞即可得到管理员用户名密码    https://www.cnblogs.com/vspid ...

  10. 将Mongodb的表导入到Hive中

    1.官方文档:https://docs.mongodb.com/ecosystem/tools/hadoop/ 2.Hive介绍: Hive特点: 1.hive是一个数据仓库,和oracle,mysq ...