PAT A1028. List Sorting (25)

浙江大学PAT 浙江大学PAT平台基本级别,都AC过了,欢迎各位下载。 立即下载

题目链接

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

Input

Each input file contains one test case. For each case, the first line contains two integers N (<=100000) 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

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函数进行活用即可,代码如下:

#include<cstdio>
#include <algorithm>
#include<cstring>
using namespace std;
struct Stu {
    int id;
    char name[10];
    int score;
};
Stu stu[100005];
int c;
bool cmp(Stu a, Stu b) {
    int s;
    switch (c) {
    case 1:return a.id < b.id;
    case 2: s = strcmp(a.name, b.name);
        if (s)return s < 0;
        else return a.id < b.id; 
    case 3: if (a.score != b.score)return a.score < b.score;
            else return a.id < b.id; 
    }
}
int main() {
    int n;
    scanf("%d %d", &n, &c);
    for (int i = 0; i < n; i++) {
        scanf("%d %s %d", &stu[i].id, stu[i].name, &stu[i].score);
    }
    sort(stu, stu + n, cmp);
    for (int i = 0; i < n; i++) {
        printf("%06d %s %d\n", stu[i].id, stu[i].name, stu[i].score);
    }
    return 0;
}



【Qt串口调试助手】1.1 - Qt5编写串口调试助手,Qt串口编程 这章来学习串口数据流操作。仿照成品制作一个自己用Qt编写的串口助手。 1. 布局UI界面 创建QWidget工程,布局UI界面:拖入2个 Plain Text Edit,作为串口数据的接收显示和发送框。 拖入几个 Combo Box 、Label 和 Push Button,使用两个Widget进行布局。如下所示。 将接收区的 Plain Text Edit,属性勾选上 readOnly,使其运行时不会被人为的输入操作影响。 加入一些弹簧,使布局美观。(有必要可以加设置不能调整.. 阅读详情

相关推荐

2024最新版Anaconda Navigator安装使用指南

本文简要介绍如何下载安装Anaconda Navigator最新版,以及如何使用Python内核搭载来完成应用程序开发。

jackson_lingua的博客 1万+

List Sorting

Excel can sort records according to any column. Now you are supposed to imitate this function. Input Each input file contains one test case. For each case, the first line contains two integers N (<=

sheng_xc的专栏 400

BAPI_OUTB_DELIVERY_CHANGE扩展指南:利用EXTENSION2与SMOD_V50B0001实现自定义字段更新

本文详细解析了如何利用BAPI_OUTB_DELIVERY_CHANGE的EXTENSION2参数与增强点SMOD_V50B0001,在不修改标准代码的前提下,安全、标准地更新SAP交货单的自定义字段。通过清晰的步骤指南和实战代码示例,帮助开发者掌握通过增强字段实现定制化业务需求的完整流程与调试技巧。

fanta的博客 451

http://pat.zju.edu.cn/contests/pat-practise/1032

1032. Sharing (25) 时间限制 100 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To store English words, one method is to use lin

我不要写标题 4228

总结所有的池化(Pooling)方法

为什么池化? 池化(Pooling)层和卷积层、全连接层一样,都是卷积神经网络的组成部分。 卷积神经网络中的卷积层会将卷积Filter应用于输入图像,以便创建特征映射来总结输入中这些特征的存在。 卷积层被证明是非常有效的,在深层模型中叠加卷积层可以让接近输入的层学习低层特征(如线条),在模型中更深(高)的层用于学习高阶或者更抽象的特征,如形状或特定对象。 卷积层特征映射输入的一个局限性是它们只能精确记录特征在输入层的位置。这意味着在输入图像中特征位置的小幅移动将导致不同的特征映射。这可以随着重新裁剪

大脸猫的博客 1万+

YOLOv11【第三章:高阶应用与落地篇·第1节】一文搞懂,YOLOv11-Seg 实例分割:Mask 原型生成与系数预测原理解析!

🏆 本文收录于专栏 《YOLOv11实战:从入门到深度优化》。本专栏围绕 YOLOv11 的改进、训练、部署与工程优化 展开,系统梳理并复现当前主流的 YOLOv11 实战案例与优化方案,内容目前已覆盖 分类、检测、分割、追踪、关键点、OBB 检测 等多个方向。

**My Coding Family** 1249

http://pat.zju.edu.cn/contests/pat-practise/1010

1010. Radix (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a pair of positive integers, for example, 6 an

我不要写标题 747

dji psdk开发 关于SDK认证芯片的使用

Payload SDK V3.10.0 于 2025-1-8 发布,增加了 Matrice 4T/4E 机型支持,同时也增加了 DJI SDK 认证芯片(DJI SDK CC)功能支持。关于认证芯片的介绍大疆 SDK 认证芯片(DJI SDK Certified Chip),简称 DJI SDK CC,用于认证基于 DJI Eport/Eport-Lite 接口开发的第三方负载设备,确保设备能够正常工作并与无人机可以进行有效通信,起到负载安全认证和功能授权的作用。

热爱生活,忠于自己 2152

http://pat.zju.edu.cn/contests/pat-practise/1015

1015. Reversible Primes (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A reversible prime in any number s

我不要写标题 1846

多物理场光学仿真软件:Lumerical_(15).多物理场耦合仿真案例分析

在多物理场光学仿真中,Lumerical 软件提供了强大的工具来模拟复杂的光学系统,包括光子学、热学、力学和电学等多物理场的耦合。本节将通过具体的案例分析,展示如何在 Lumerical 中进行多物理场耦合仿真的开发和实现。我们将从简单的热光效应仿真入手,逐步深入到更复杂的多物理场耦合场景,如光电效应和光力学效应。每个案例都将包括详细的原理说明和具体的代码示例,帮助读者更好地理解和应用这些技术。

kkchenjj的博客 1023

在 SAP 中,Primary Cost Element(初级成本要素)与Secondary Cost Element(次级成本要素)的核心区别、作用及业务含义可归纳如下

摘要:SAP中初级成本要素与次级成本要素的核心区别在于:初级要素必须关联FI模块的损益科目,直接影响财务报表,用于记录外部成本(如电费、薪酬);次级要素仅存在于CO模块,用于内部成本分配(如分摊、作业分配),不影响外部报表。初级要素是"外部成本入口",次级要素是"内部成本搬运工",二者共同实现成本的多维度追踪与管理。

金牌架构师 762

PAT - 浙江大学计算机程序设计能力考试简介

日期: 2012-02-27 摘要: PAT - 浙江大学计算机程序设计能力考试简介 宗 旨 浙江大学计算机程序设计能力考试(Programming Ability Test,简称PAT)是由浙江大学计算机科学与技术学院组织的统一考试,旨在培养和展现学生分析问题、解决问题和计算机程序设计的能力,科学评价计算机程序设计人才。 影响力 浙江大学计算机科学与技术学院

一步步,一寸寸,一点点,一天天,慢慢来 1万+

YOLO26 多任务统一架构:检测 / 分割 / 姿态 / OBB 设计

YOLO26提出了一种多任务统一架构,整合了目标检测、实例分割、姿态估计和旋转框检测(OBB)四大计算机视觉任务。该架构采用共享Backbone和Neck的设计,配合轻量级任务特定Head,解决了传统方法中多模型并行带来的高开发成本、大内存占用和低推理效率问题。核心设计包括:1)共享特征提取层实现参数复用;2)模块化Head结构支持灵活任务组合;3)统一接口实现单模型多任务处理。实验表明,该架构在保持各任务性能的同时显著提升了系统效率,为多任务视觉系统提供了新的实现范式。

一键难忘的博客 706

PAT A1028 List Sorting (25分)

PAT甲级:A1028 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...

只想用最简短的代码刷题 202

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

PAT A1028 List Sorting (25 分)

PAT A1028 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 (≤10^​5​​ ) and

weixin_48165493的博客 135

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

PAT A 1028 List Sorting (25 分)

思路 想偷鸡,但不行(超时警告)。感受到莫大痛苦。

Siumai's Blog 229

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

1028 List Sorting (25 分)——PAT A

1028List 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, t...

weixin_42769575的博客 145

PAT A 1028 List Sorting (25分)

1028 List Sorting (25分) 吐槽 极速编程二连。基础的sort函数应用。 不过如果不是C用不了sort函数可能写排序代码得要一会儿? (所以C++好啊!) 逻辑 就是实现三个cmp函数嘛。 坑点 再用int表达定位数ID我就把自己手剁下来。 题目 Excel can sort records according to any column. Now you are suppos...

虚境的博客 145

PAT:A1028 List Sorting (25 分)

PAT:A1028 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 ca...

Ecloss 308

PAT-A 1028 List Sorting (25 分)

分析:水题,同样是25分的题,这题只是A1012的一部分,和A1016更是没法比。

qq_38127801的博客 127

pat 甲级A1028 List Sorting (25分)

题目链接: https://pintia.cn/problem-sets/994805342720868352/problems/994805468327690240 题目分析: 多混合排序问题。对不同键值进行排序。问题是写比较函数。注意:若将姓名定义成string类型超时。 不知道大家有没有出现这样的情况。望指正。 参考代码: #include <algorithm...

dutmathjc的博客 200

pat 甲级 排序 A1028 List Sorting (25分)

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 (≤10​5​​) and C, wh

weixin_42358356的博客 131

PAT A1028 List Sorting (25 分) 排序

题目大意:给出N个学生的id、name、grade信息,根据输入选择排序的尺度进行排序并输出。 按要求排序即可,使用函数指针可以稍微缩短代码长度。 AC代码: #include <algorithm> #include <cstdio> #include <cstring> using namespace std; struct ...

HackingGate的博客 165
上一篇: A1012. The Best Rank (25)
下一篇: PAT A1055. The World's Richest (25)
DemonInside
博客等级 码龄10年 1粉丝 18原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值