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
分析:就是排序的一道题 要注意不能使用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 分)的更多相关文章
- PAT 甲级 1028 List Sorting (25 分)(排序,简单题)
1028 List Sorting (25 分) Excel can sort records according to any column. Now you are supposed to i ...
- PAT 1028 List Sorting (25分) 用char[],不要用string
题目 Excel can sort records according to any column. Now you are supposed to imitate this function. In ...
- 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 ...
- 【PAT甲级】1028 List Sorting (25 分)
题意: 输入一个正整数N(<=100000)和C(C属于{1,2,3}),接下来输入N行,每行包括学生的六位学号(习惯用string输入,因为可能有前导零),名字和成绩(正整数).输出排序后的信 ...
- PAT 甲级 1052 Linked List Sorting (25 分)(数组模拟链表,没注意到不一定所有节点都在链表里)
1052 Linked List Sorting (25 分) A linked list consists of a series of structures, which are not ne ...
- 【PAT】1028. List Sorting (25)
题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1028 题目描述: Excel can sort records according to an ...
- PAT 甲级 1028. List Sorting (25) 【结构体排序】
题目链接 https://www.patest.cn/contests/pat-a-practise/1028 思路 就按照 它的三种方式 设计 comp 函数 然后快排就好了 但是 如果用 c++ ...
- 1028. List Sorting (25)
#include <vector> #include <stdio.h> #include <string.h> #include <algorithm> ...
- PAT (Advanced Level) 1028. List Sorting (25)
时间卡的比较死,用string会超时. #include<cstdio> #include<cstring> #include<cmath> #include< ...
随机推荐
- Spring、SpringMVC、SpringBoot、SpringCloud的区别和联系
简介 Spring是一个轻量级的控制反转(IOC)和面向切面(AOP)的容器框架.Spring能够让我们编写出更简洁.易于管理.更易于测试的代码. SpringMVC是Spring的一个模块,一个we ...
- 以正确的方式下载和配置 ASP.NET Core 官方源码
我们可以在Github上面直接查看ASP.NET Core 3.x的源代码,但是我们也可以把源代码下载下来进行查看. 而下载源代码进行查看有很多好处: 任意的导航源代码 内置了一个示例项目 直接调试源 ...
- TCP粘包很难么,为何我屡屡受挫??
无论走到哪里,都应该记住,过去都是假的,回忆是一条没有尽头的路,一切以往的春天都不复存在,就连那最坚韧而又狂乱的爱情归根结底也不过是一种转瞬即逝的现实. --马尔克斯 本文已经收录至我的GitHub, ...
- ubuntu16.04 + caffe + SSD + gpu 安装
昨天我们买好了硬件,今天我们开始安装caffe了,我本人安装过caffe不下10次,每次都是一大堆问题,后来终于总结了关键要点,就是操作系统. 1. 千万不要用ubuntu17.10来安装, 2. 最 ...
- Django中ORM中的get与filter区别
本文出自 “orangleliu笔记本” 博客,出处http://blog.csdn.net/orangleliu/article/details/38597593 Django的orm中get和fi ...
- css 固比固模型
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 03-Vue数据请求
1. vue-resource vue-resource jsonp请求 <body> <div id="app"> <!-- v-model 监听表 ...
- 【spring springmvc】springmvc使用注解声明控制器与请求映射
目录 概述 壹:注解说明 贰:实现注解声明控制器与请求映射 一:使用controller 二:配置包扫描与视图解析器 1.配置包扫描 2.配置试图解析器 三:配置部署描述符 1.读取spring-mv ...
- 【Weiss】【第03章】练习3.25:数组模拟队列
[练习3.25] 编写实现队列的例程,使用 a.链表 b.数组 Answer: 在这章一开头就已经写了个链表的队列例程了,所以实际上只要做b小题就可以. 数组模拟队列和链表的两点小不同是: ①.数组空 ...
- Redis基本数据类型、数据持久化、过期策略及淘汰机制
一点技术.技术乐享!!! 如果有人问你:Redis这么快,他的“多线程模式”你了解吗? 请回答他:您是想问Redis这么快,为什么还是单线程模式吗? redis是什么 简单来说redis是C语言开发的 ...