17冬第二题 PAT甲级 1141 Ranking of Institutions (25分) 有点鸡贼

杭电oj2023题题目详解(Java版) 杭电oj2023题详解 阅读详情

题目

After each PAT, the PAT Center will announce the ranking of institutions based on their students' performances. Now you are asked to generate the ranklist.

Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N (≤10​5​​), which is the number of testees. Then N lines follow, each gives the information of a testee in the following format:

ID Score School

where ID is a string of 6 characters with the first one representing the test level: B stands for the basic level, A the advanced level and T the top level; Score is an integer in [0, 100]; and School is the institution code which is a string of no more than 6 English letters (case insensitive). Note: it is guaranteed that ID is unique for each testee.

Output Specification:

For each case, first print in a line the total number of institutions. Then output the ranklist of institutions in nondecreasing order of their ranks in the following format:

Rank School TWS Ns

where Rank is the rank (start from 1) of the institution; School is the institution code (all in lower case); ; TWS is the total weighted score which is defined to be the integer part of ScoreB/1.5 + ScoreA + ScoreT*1.5, where ScoreX is the total score of the testees belong to this institution on level X; and Ns is the total number of testees who belong to this institution.

The institutions are ranked according to their TWS. If there is a tie, the institutions are supposed to have the same rank, and they shall be printed in ascending order of Ns. If there is still a tie, they shall be printed in alphabetical order of their codes.

Sample Input:

10
A57908 85 Au
B57908 54 LanX
A37487 60 au
T28374 67 CMU
T32486 24 hypu
A66734 92 cmu
B76378 71 AU
A47780 45 lanx
A72809 100 pku
A03274 45 hypu

Sample Output:

5
1 cmu 192 2
1 au 192 3
3 pku 100 1
4 hypu 81 2
4 lanx 81 2

题意

致谢:https://blog.youkuaiyun.com/liuchuo/article/details/79618766

给出每个学生的id、分数、学校,学校名称不区分大小写,输出学校排名、学校名称、总加权成绩、学校参赛人数。学校名称输出时候以小写方式输出。

分析

致谢:https://blog.youkuaiyun.com/liuchuo/article/details/79618766

1.两个unordered_map,一个用来存储某学校名称对应的参赛人数,另一个计算某学校名称对应的总加权成绩

2.对于排名的处理:设立pres表示前一个学校的加权总分,如果pres和当前学校的加权总分不同,说明rank等于数组下标+1,否则rank不变

陷阱

1.结果是截取的整数
计数的时候存浮点数,存到结果的时候就要截取成整数,输出的时候也是整数。这三个地方反过来一个都不行。

2.map会超时
1153同款操作,只能用unordered_map

3.排名
分、人数、代号都要参加排序,自己写排序函数

4.学校名要存小写
没有现成的转换库函数,要自己写

int j=0;
while(j<sn.size()){
    sn[j]=tolower(sn[j]);
     j++;
}


满分代码一

#include<iostream>
#include<vector>
#include<unordered_map>
#include<cctype>
using namespace std;
int n,m;
string si,sn;
struct school{
    string id;
    int score,number;
};
bool cmp(school &a,school &b){
    if(a.score!=b.score)return a.score>b.score;
    else if(a.number!=b.number) return a.number<b.number;
    else return a.id<b.id;
}
int main(){
    scanf("%d",&n);
    unordered_map<string,double> m1;
    unordered_map<string,int> m2;
    for(int i=0;i<n;i++){
        cin>>si>>m>>sn;
        int j=0;
        while(j<sn.size()){
            sn[j]=tolower(sn[j]);
            j++;
        }
        if(si[0]=='A')m1[sn]+=m;
        else if(si[0]=='B')m1[sn]+=m/1.5;
        else if(si[0]=='T')m1[sn]+=m*1.5;
        m2[sn]++;
    }
    vector<school> v;
    for(auto it:m1){
        v.push_back({it.first,(int)it.second,m2[it.first]});
    }
    printf("%d\n",v.size());
    sort(v.begin(),v.end(),cmp);
    int rank=1,total=1,pre=0;
    for(auto it:v){
        if(total==1){
            printf("1 %s %d %d\n",it.id.c_str(),it.score,it.number);
        }else{
            if(it.score==pre){
                printf("%d %s %d %d\n",rank,it.id.c_str(),it.score,it.number);
            }else {
                printf("%d %s %d %d\n",total,it.id.c_str(),it.score,it.number);
                rank=total;
            }
        }
        pre=it.score;
        total++;
    }
    return 0;
}




满分代码二(也可以用set+运算符重载来代替向量的排序) 

#include<iostream>
#include<unordered_map>
#include<cctype>
#include<set>
using namespace std;
int n,m;
string si,sn;
struct school{
    string id;
    int score,number;
    bool operator < (const school &a) const{
        if(a.score!=score)return a.score<score;
        else if(a.number!=number) return a.number>number;
        else return a.id>id;
    }
};
set<school> s;
int main(){
    scanf("%d",&n);
    unordered_map<string,double> m1;
    unordered_map<string,int> m2;
    for(int i=0;i<n;i++){
        cin>>si>>m>>sn;
        for(int j=0;j<sn.size();j++) sn[j]=tolower(sn[j]);
        if(si[0]=='A')m1[sn]+=m;
        else if(si[0]=='B')m1[sn]+=m/1.5;
        else if(si[0]=='T')m1[sn]+=m*1.5;
        m2[sn]++;
    }
    for(auto it:m1){
        s.insert({it.first,(int)it.second,m2[it.first]});
    }
    printf("%d\n",s.size());
    int rank=1,total=1,pre=0;
    for(auto it:s){
        if(total==1){
            printf("1 %s %d %d\n",it.id.c_str(),it.score,it.number);
        }else{
            if(it.score==pre){
                printf("%d %s %d %d\n",rank,it.id.c_str(),it.score,it.number);
            }else {
                printf("%d %s %d %d\n",total,it.id.c_str(),it.score,it.number);
                rank=total;
            }
        }
        pre=it.score;
        total++;
    }
    return 0;
}

彩蛋

hpyu 哈佛大学、耶鲁大学和普林斯顿大学的合称

lanx 蓝翔

au 美利坚大学等好几所国外的大学/软件Au/金元素

pku 北京大学(陈越姥姥母校)

cmu 卡耐基梅隆大学

推荐阅读:2020年7月PAT甲级满分必备刷题技巧

Cesium中GLB模型加载 Cesium中GLB模型加载全解析:Primitive与Entities方法详解 阅读详情

相关推荐

SAP STO流程实战:如何配置外向交货单PGI后自动生成内向交货单(附避坑指南)

本文详细解析了SAP STO流程中,如何配置实现外向交货单发货过账(PGI)后自动生成内向交货单。通过分步指南,重点阐述了SPED输出类型、输出条件记录、收货点及确认控制码等关键配置,并提供了针对“No goods receipt possible”等常见错误的避坑指南,助力实现跨公司物料转移流程的自动化与高效衔接。

weixin_28327051的博客 395

2017年冬季浙大PAT真题(附本人代码)

  1076. Wifi密码 (15) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 下面是微博上流传的一张照片:“各位亲爱的同学们,鉴于大家有时需要使用wifi,又怕耽误亲们的学习,现将wifi密码设置为下列数学题答案:A-1;B-2;C-3;D-4;请同学们自己作答,每两日一换。谢谢...

s136424的博客 9057

MOS管开关设计知识-(五种MOS管开关电路图方式)

在使用MOS管设计开关电源或者马达驱动电路的时候,大部分人都会考虑MOS的导通电阻,最大电压等,最大电流等,也有很多人仅仅考虑这些因素。这样的电路也许是可以工作的,但并不是优秀的,作为正式的产品设计也是不允许的。 下面是我对MOSFET及MOSFET驱动电路基础的一点总结,其中参考了一些资料,非全部原创。包括MOS管的介绍,特性,驱动以及应用电路。 1、MOS管种类和结构 MOSFET管是FET的...

树卡花 7万+

pat甲级 1141 PAT Ranking of Institutions (25分)

文章目录1.错误代码1.1测试结果 pat甲级 1141 PAT Ranking of Institutions (25分) 1.错误代码 #include <iostream> #include <cctype> #include <unordered_map> #include <vector> #include <algorithm> using namespace std; struct node {int score,ns;}; un

qq_44992782的博客 285

雾化器硬件设计:从N155驱动到PCB可量产实现

雾化器是典型的机电一体化嵌入式终端,其硬件设计本质是电源完整性、信号完整性与热-机械协同的系统工程。核心在于理解高压脉冲驱动原理(如2.4MHz固定频率匹配压电谐振)、电源域隔离机制(AGND/DGND/PGND分域设计)及约束驱动的PCB转化逻辑。技术价值体现在电气可靠性(如OTP/OLP保护)、生产可制造性(DFM合规焊盘与钢网)与环境鲁棒性(三防漆、散热过孔)。典型应用场景覆盖加湿器、医疗雾化仪与工业微流控设备。本文聚焦超声波雾化控制板的硬线实现路径,深入解析N155驱动芯片选型、网络标签工程误用陷阱

weixin_35649491的博客 617

Prompt进阶2:LangGPT(构建高性能Prompt策略和技巧)--最佳实践指南

Prompt进阶2:LangGPT(构建高性能Prompt策略和技巧)--最佳实践指南

丨汀、的博客 2650

【PAT甲级 - C++题解】1141 PAT Ranking of Institutions

📣专栏定位:为想考甲级PAT的小伙伴整理常考算法题解,祝大家都能取得满分!

Newin2020的博客 411

超详细教程YoloV8官方推荐免费数据集网站Roboflow一键导出Voc、COCO、Yolo、Csv等格式

YoloV8官方推荐了一个数据集网站,就是Roboflow。Roboflow是一个数据集管理平台,提供了免费的数据集,同时也支持上传自己的数据集进行格式转换。使用Roboflow,开发者可以方便地获取所需格式的数据集,无需手动转换格式。此外,Roboflow还提供了多种数据预处理、数据增强等功能,可帮助开发者更好地优化训练数据

Snu77的博客 2万+

【PAT甲级A1141】 PAT Ranking of Institutions (25分)(c++)

1141 PAT Ranking of Institutions (25分) 作者:CHEN, Yue 单位:浙江大学 代码长度限制:16 KB 时间限制:400 ms 内存限制:64 MB After each PAT, the PAT Center will announce the ranking of institutions based on their students’ performances. Now you are asked to generate the ranklist. Inpu

小庄同学的博客 174

3. 动手运行第一个 SAP Fiori Elements 应用(ListReport 类型)

这个代理服务器能够自动监听我们 Fiori Elements 应用里向 ES5 Demo 系统发送的 OData 请求,拦截这个请求,并通过 Node.js 代码向 ES5 服务器转发,拿到响应数据后再交还给 Fiori Elements 应用。后者对自己发出的请求被代理这件事情一无所知。本文的任务是,大家按照我的介绍,在本地成功运行笔者准备的这个 Fiori Elements 应用。的错误消息, 说明大家安装的 Node.js 版本没有达到本地运行 Fiori Elements 的最低要求。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1671

新手必看!手把手教你如何在飞牛NAS上玩转Docker容器!(飞牛Nas(fnOS)如何创建Docke容器以及Compose部署项目)

新手必看!手把手教你如何在飞牛NAS上玩转Docker容器!(飞牛Nas(fnOS)如何创建Docke容器以及Compose部署项目)

XiaoqiangClub的博客 1万+

PAT 甲级 1141  PAT Ranking of Institutions

1141PAT Ranking of Institutions(25 point(s)) After each PAT, the PAT Center will announce the ranking of institutions based on their students' performances. Now you are asked to generate the rankli...

漫浸天空的雨色的备忘录~ 743

【Simulink教程案例7】基于Simulink的滑模控制器设计与实现

欢迎订阅滑膜控制是一种变结构控制策略,其和常规控制方法的主要区别在于控制的不连续性,即一种使系统结构随时间变化的开关特性。所以,滑膜控制器也叫做变结构控制器,其本质是一类特殊的非线性控制器,并且这种非线性为不连续性。滑膜控制器和其他控制方式最大的区别在于其结构的不固定性,在其工作过程中,系统当前的状态会发生变化,使得系统按照预先设置的“滑动模态”的状态轨迹运动。正是由于这个特点,滑膜控制器具有快速响应的优点。滑模控制的基本定义如下所示:1).穿越切换面上的某个点;2).从切换面上的某个点离开;

FPGA/MATLAB学习教程/源码/项目合作开发 3240

PAT 1141. PAT Ranking of Institutions (25) - 甲级

1141. PAT Ranking of Institutions (25)After each PAT, the PAT Center will announce the ranking of institutions based on their students’ performances. Now you are asked to generate the ranklist.Input S...

柳婼 の blog 2803

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

PAT甲级1141 PAT Ranking of Institutions (25 分)

1141PAT Ranking of Institutions(25分) After each PAT, the PAT Center will announce the ranking of institutions based on their students' performances. Now you are asked to generate the ranklist. In...

Dexter 212

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

PAT(甲级)1141.PAT Ranking of Institutions (25 分)

PAT 1141.PAT Ranking of Institutions (25 分) After each PAT, the PAT Center will announce the ranking of institutions based on their students’ performances. Now you are asked to generate the ranklist. ...

乐行僧的博客 524

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

PAT甲级A1141 PAT Ranking of Institutions (25 分)

After each PAT, the PAT Center will announce the ranking of institutions based on their students' performances. Now you are asked to generate the ranklist. Input Specification: Each input file conta...

vir_lee的博客 350

PAT_甲级_1141 PAT Ranking of Institutions (25point(s)) (C++)【模拟/结构体排序】

目录 1,题目描述 题目大意 2,思路 数据结构 算法 3,AC代码 4,解题过程 第一搏 第二搏 1,题目描述 Sample Input: 10 A57908 85 Au B57908 54 LanX A37487 60 au T28374 67 CMU T32486 24 hypu A66734 92 cmu B76378 71 AU A47780 45 lanx...

&再见萤火虫&的博客 495

PAT——1141 PAT Ranking of Institutions 甲级

1141 PAT Ranking of Institutions题目题意题目解析注意AC代码参考 题目 https://pintia.cn/problem-sets/994805342720868352/problems/994805344222429184 题意 题目会给出N个学生的ID、分数、学校,要求在统计每个学校的总人数和总分数后,按要求输出 题目解析 通过map存储每一个学校的相关信息,之后遍历map将元素存入ans的vector向量中,再按照题目要求对ans排序,最后按照排名输出即可 注意 成员

ljhsq的博客 156

PAT甲级 1141 PAT Ranking of Institutions (25分) map/C++

1141 PAT Ranking of Institutions (25分) 题目大意:给定考生ID,分数,学校,要求对各个学校总分进行排名。 tips: 学校code需要全部转换为小写 按照分数排名,如果分数相同,按照考生人数从小到大排列,如果考生人数相同,则按照字母表顺序排列。 分数需要到最后再转化为int(测试点5) 如果用map超时,可以考虑使用unorder_map(不过我用map并没有超时) #include<iostream> //输入输出流头

qq_43955154的博客 251

PAT甲级1141 PAT Ranking of Institutions (25分)|C++实现

一、题目描述 原题链接 After each PAT, the PAT Center will announce the ranking of institutions based on their students’ performances. Now you are asked to generate the ranklist. Input Specification: ​​Output Specification: Sample Input: 10 A57908 85 Au B57908 54 L

weixin_42393947的博客 181

PAT 甲级1141 PAT Ranking of Institutions

1141 PAT Ranking of Institutions After each PAT, the PAT Center will announce the ranking of institutions based on their students’ performances. Now you are asked to generate the ranklist. Input Specification: Each input file contains one test case. For ea

cyberickk blog 204

【PAT刷题甲级】1141.PAT Ranking of Institutions

1141 PAT Ranking of Institutions (25 分) After each PAT, the PAT Center will announce the ranking of institutions based on their students’ performances. Now you are asked to generate the ranklist. Input Specification Each input file contains one test case.

C_greenbird的博客 261

pat 甲级 排序A1141 PAT Ranking of Institutions (25分)

1141 PAT Ranking of Institutions (25分) After each PAT, the PAT Center will announce the ranking of institutions based on their students' performances. Now you are asked to generate the ranklist. Input Specification: Each input file contains one test cas

weixin_42358356的博客 154

PAT 甲级 1141 PAT Ranking of Institutions

https://pintia.cn/problem-sets/994805342720868352/problems/994805344222429184 After each PAT, the PAT Center will announce the ranking of institutions based on their students' performances. Now yo...

weixin_30528371的博客 101

1141 PAT Ranking of Institutions (25point(s)) - C语言 PAT 甲级

* 从题目上也可看出,又是一道排序题

有三只土豆 167
上一篇: 18冬第二题 PAT甲级 1153 Decode Registration Card of PAT (25分) 鸡贼的题
下一篇: 17秋第二题 PAT甲级 1137 Final Grading (25分) 给的规则有点多
浒鱼鱼
博客等级 码龄11年 287粉丝 70原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值