当前位置:网站首页>1028 List Sorting
1028 List Sorting
2022-06-27 17:53:00 【Brosto_Cloud】
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 (≤105) 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 9
Sample Output 3:
000002 James 9
000001 Zoe 60
000007 James 85
000010 Amy 90#include <iostream>
#include <algorithm>
using namespace std;
struct Stu {
string id;
string name;
int grade;
} a[100010];
bool cmp1(Stu s1, Stu s2) {
return s1.id < s2.id;
}
bool cmp2(Stu s1, Stu s2) {
return s1.name == s2.name ? s1.id < s2.id : s1.name < s2.name;
}
bool cmp3(Stu s1, Stu s2) {
return s1.grade == s2.grade ? s1.id < s2.id : s1.grade < s2.grade;
}
int main() {
int n, c;
cin >> n >> c;
for (int i = 0; i < n; i++) {
cin >> a[i].id >> a[i].name >> a[i].grade;
}
if (c == 1) {
sort(a, a + n, cmp1);
} else if (c == 2) {
sort(a, a + n, cmp2);
} else if (c == 3) {
sort(a, a + n, cmp3);
}
for (int i = 0; i < n; i++) {
cout << a[i].id << ' ' << a[i].name << ' ' << a[i].grade << endl;
}
return 0;
}
边栏推荐
- NVIDIA Clara-AGX-Developer-Kit installation
- 谈谈线程安全
- Google Earth Engine(GEE)——ImageCollection (Error)遍历影像集合产生的错误
- 如何封裝調用一個庫
- 基于STM32F103ZET6库函数蜂鸣器实验
- 带你认识图数据库性能和场景测试利器LDBC SNB
- Four years of College for an ordinary graduate
- Informatics Orsay all in one 1335: [example 2-4] connected block
- CDGA|交通行业做好数字化转型的核心是什么?
- New Zhongda chongci scientific and Technological Innovation Board: annual revenue of 284million and proposed fund-raising of 557million
猜你喜欢

Bit. Store: long bear market, stable stacking products may become the main theme

C# 二维码生成、识别,去除白边、任意颜色

Blink SQL built in functions

Solution of adding st-link to Huada MCU Keil
![[elt.zip] openharmony paper Club - memory compression for data intensive applications](/img/b3/ab915f0338174cba1a003edc262a5d.png)
[elt.zip] openharmony paper Club - memory compression for data intensive applications

xctf攻防世界 MISC薪手进阶区

数仓的字符截取三胞胎:substrb、substr、substring

爬取国家法律法规数据库

New Zhongda chongci scientific and Technological Innovation Board: annual revenue of 284million and proposed fund-raising of 557million

如何实现IM即时通讯“消息”列表卡顿优化
随机推荐
openssl客户端编程:一个不起眼的函数导致的SSL会话失败问题
《第五项修炼》(The Fifth Discipline):学习型组织的艺术与实践
One week technical update express of substrate and Boca 20220425 - 20220501
CDGA|交通行业做好数字化转型的核心是什么?
数仓的字符截取三胞胎:substrb、substr、substring
Is Guosen Securities a state-owned enterprise? Is it safe to open an account with Guosen Securities?
CMS 执行的七个阶段
Jinyuan's high-end IPO was terminated: it was planned to raise 750million Rushan assets and Liyang industrial investment were shareholders
Buzzer experiment based on stm32f103zet6 library function
广发期货开户安全吗?
Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
Informatics Olympiad 1333: [example 2-2] blah data set | openjudge noi 3.4 2729:blah data set
芯动联科冲刺科创板:年营收1.7亿 北方电子院与中城创投是股东
Error reported by Huada MCU Keil_ Weak's solution
【云驻共创】高校数字化差旅建设“解决之道”
Informatics Orsay all in one 1335: [example 2-4] connected block
从感知机到前馈神经网络的数学推导
国际数字经济学院、华南理工 | Unified BERT for Few-shot Natural Language Understanding(用于小样本自然语言理解的统一BERT)
工作流自动化 低代码是关键
过关斩将,擒“指针”(下)