题目

中规中矩的一道题。排名的顺序一开始没太明白,但是理解之后写起来挺流畅的,没什么坑。

解题思路:题目会给出所有学生所有科目的成绩、想要看分学生的学号。

  • 我们要先给这些学生单科成绩排序,算出它们的单科排名,存在Stu
  • 再依次输出想要看分的学生的最好成绩(最好成绩的学科 最好成绩的排名)。如果学号不存在,就输出N/A



题解 C++

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
class Stu {public:string id;int C, CC;//C分数 CC排名int M, MM;int E, EE;int A, AA;
};
//自定义排序函数:大在前
int cmpC(Stu a, Stu b) {return(a.C > b.C);
}
int cmpM(Stu a, Stu b) {return(a.M > b.M);
}
int cmpE(Stu a, Stu b) {return(a.E > b.E);
}
int cmpTotal(Stu a, Stu b) {return(a.A > b.A);
}int main() {int n, m;cin >> n >> m;Stu stu[2000];int count = 0;string id;int  C, M, E;for (int i = 0; i < n; i++) {cin >> id >> C >> M >> E;stu[count].id = id;stu[count].C = C;stu[count].M = M;stu[count].E = E;stu[count].A = C + M + E;count++;}string want[2000];for (int i = 0; i < m; i++) {cin >> want[i];}//排序优先级 C->M->E->Totalstable_sort(stu, stu + count, cmpTotal);stu[0].AA = 1;for (int i = 0; i < count; i++) {//存A排名,注意一下并列情况下的排名技巧int curRank = 1;if (stu[i].A == stu[i - 1].A) {stu[i].AA = stu[i - 1].AA;}else {stu[i].AA = curRank = i + 1;}}stable_sort(stu, stu + count, cmpE);stu[0].EE = 1;for (int i = 0; i < count; i++) {//存E排名int curRank = 1;if (stu[i].E == stu[i - 1].E) {stu[i].EE = stu[i - 1].EE;}else {stu[i].EE = curRank = i + 1;}}stable_sort(stu, stu + count, cmpM);stu[0].MM = 1;for (int i = 0; i < count; i++) {//存M排名int curRank = 1;if (stu[i].M == stu[i - 1].M) {stu[i].MM = stu[i - 1].MM;}else {stu[i].MM = curRank = i + 1;}}stable_sort(stu, stu + count, cmpC);stu[0].CC = 1;for (int i = 0; i < count; i++) {//存C排名int curRank = 1;if (stu[i].C == stu[i - 1].C) {stu[i].CC = stu[i - 1].CC;}else {stu[i].CC = curRank = i + 1;}}//输出科目优先级:A C M Ebool find = false;for (int i = 0; i < m; i++) {find = false;for (int j = 0; j < n; j++) {if (stu[j].id == want[i]) {find = true;if (stu[j].AA <= stu[j].CC && stu[j].AA <= stu[j].MM && stu[j].AA <= stu[j].EE) {cout << stu[j].AA << " A\n";}else if (stu[j].CC <= stu[j].AA && stu[j].CC <= stu[j].MM && stu[j].CC <= stu[j].EE) {cout << stu[j].CC << " C\n";}else if (stu[j].MM <= stu[j].AA && stu[j].MM <= stu[j].CC && stu[j].MM <= stu[j].EE) {cout << stu[j].MM << " M\n";}else  if (stu[j].EE <= stu[j].AA && stu[j].EE <= stu[j].CC && stu[j].EE <= stu[j].MM) {cout << stu[j].EE << " E\n";}break;}}if (!find) {cout << "N/A\n";}}system("pause");
}

【PAT甲级 排序】1012 The Best Rank (25 分) C++ 全部AC相关推荐

  1. 【PAT甲级 排序】1096 Consecutive Factors (20 分) C++ 全部AC

    题目 难倒是不难,暴力破解即可.要注意的就是开longlong,以及开方时,不要丢失临界值,还有如果子序列长度为0的话,输出num本身(因为计算的时候不考虑1这个因数). 一开始想出来一种O(n)的算 ...

  2. PAT 1012 The Best Rank (25 分)

    1012 The Best Rank (25 分) 今天给大家分享的是PAT甲级的一道小题,设计题 原题请点击我 简单翻译: 设计一个排名表,这个表中以学生ID为主键,C表示程序设计语言的成绩,M表示 ...

  3. PAT甲级1066 Root of AVL Tree (25分):[C++题解]建立平衡树(AVL树)

    文章目录 题目分析 题目链接 题目分析 图片来源:acwing 分析 平衡树(AVL树)是平衡二叉搜索树的简称,当然需要满足二叉搜索树的性质,左子树小于根,根小于等于右子树:然后还要满足平衡树的基本特 ...

  4. PAT甲级真题(结构体排序)——1012. The Best Rank (25)

    1012. The Best Rank (25) To evaluate the performance of our first year CS majored students, we consi ...

  5. 【解析】1012 The Best Rank (25 分)

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 To evaluate the performance of our first year CS majored students ...

  6. 1012 The Best Rank (25 分)【难度: 中 / 知识点: 排序 前缀和】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805502658068480 解析: 这里的每一项排名有一个坑的点,就是 ...

  7. 【PAT - 甲级1017】Queueing at Bank (25分)(优先队列,模拟)

    题干: Suppose a bank has K windows open for service. There is a yellow line in front of the windows wh ...

  8. 【PAT甲级 - 1013】Battle Over Cities (25分)(并查集)

    题干: It is vitally important to have all the cities connected by highways in a war. If a city is occu ...

  9. 【PAT甲级】1062 Talent and Virtue (25分)

    解题过程的小记录,如有错误欢迎指出. 小导航~ 题目分析 注意点 我的解题过程 思路 bug 代码 dalao的代码 借鉴点 题目分析 对一组人的德才分按照给定的规则进行排序 注意点 弄清楚一共分为四 ...

最新文章

  1. 我和freelancer不得不说的故事5 --- 心理落差
  2. 配置sctp_5G站点网优参数配置指导书
  3. RoR开发环境搭建 RAILS install log
  4. 开发工具:Intellij IDEA 非常实用的小技巧,你确定不来看看?
  5. iphone11什么时候上市_hd3手表高仿哪里买 什么时候上市?
  6. python 用元类 type 实现对数据库的ORM 映射
  7. php 图片后缀,PHP如何实现图片无后缀
  8. Eclipse MySql之登录
  9. 2018安卓应用安全白皮书:超98%安卓应用存有安全风险
  10. 【Flink】A Typical reason for AskTimeOutException is that the recipientactor
  11. leetcode题库:2.两数相加
  12. 小数点保留若干位小数 %.*f
  13. python round_python round()
  14. XP cmd命令 部分
  15. 牛逼! IDEA 2020 要本土化,真的是全中文了!中国开发者话语权越来越大了
  16. 4.28下午 听力611
  17. java计算机毕业设计幼儿园管理系统源码+数据库+系统+lw文档+部署
  18. PBS常用基本命令------PBS入门
  19. 计算机网络里面ap是什么,网络ap是什么意思
  20. IMDB数据看影响电影票房的因素分析

热门文章

  1. POJ - 1655 Balancing Act(树的重心)
  2. 华为p4用鸿蒙系统吗_华为正式发布鸿蒙OS Beta版,网友:荣耀还能用上鸿蒙吗
  3. 2013年东北赛B题(数位DP)
  4. Duilib教程-HelloDuilib及DuiDesigner的简单使用
  5. FFMPEG音视频解码
  6. 程序员的吸星大法-IDA反汇编工具初探
  7. 动态语言和静态语言的比较
  8. 完成端口(Completion Port)详解----- By PiggyXP(小猪)
  9. 图文详解CDC技术,看这一篇就够了!
  10. 音视频技术开发周刊 | 216