1095 解码PAT准考证/1153 Decode Registration Card of PAT(25 分)

PAT 准考证号由 4 部分组成:

  • 第 1 位是级别,即 T 代表顶级;A 代表甲级;B 代表乙级;
  • 第 2~4 位是考场编号,范围从 101 到 999;
  • 第 5~10 位是考试日期,格式为年、月、日顺次各占 2 位;
  • 最后 11~13 位是考生编号,范围从 000 到 999。

现给定一系列考生的准考证号和他们的成绩,请你按照要求输出各种统计信息。

输入格式:

输入首先在一行中给出两个正整数 N(≤10​4​​)和 M(≤100),分别为考生人数和统计要求的个数。

接下来 N 行,每行给出一个考生的准考证号和其分数(在区间 [0,100] 内的整数),其间以空格分隔。

考生信息之后,再给出 M 行,每行给出一个统计要求,格式为:类型 指令,其中

  • 类型 为 1 表示要求按分数非升序输出某个指定级别的考生的成绩,对应的 指令 则给出代表指定级别的字母;
  • 类型 为 2 表示要求将某指定考场的考生人数和总分统计输出,对应的 指令 则给出指定考场的编号;
  • 类型 为 3 表示要求将某指定日期的考生人数分考场统计输出,对应的 指令 则给出指定日期,格式与准考证上日期相同。

输出格式:

对每项统计要求,首先在一行中输出 Case #: 要求,其中 # 是该项要求的编号,从 1 开始;要求 即复制输入给出的要求。随后输出相应的统计结果:

  • 类型 为 1 的指令,输出格式与输入的考生信息格式相同,即 准考证号 成绩。对于分数并列的考生,按其准考证号的字典序递增输出(题目保证无重复准考证号);
  • 类型 为 2 的指令,按 人数 总分 的格式输出;
  • 类型 为 3 的指令,输出按人数非递增顺序,格式为 考场编号 总人数。若人数并列则按考场编号递增顺序输出。

如果查询结果为空,则输出 NA

输入样例:

8 4
B123180908127 99
B102180908003 86
A112180318002 98
T107150310127 62
A107180908108 100
T123180908010 78
B112160918035 88
A107180908021 98
1 A
2 107
3 180908
2 999

输出样例:

Case 1: 1 A
A107180908108 100
A107180908021 98
A112180318002 98
Case 2: 2 107
3 260
Case 3: 3 180908
107 2
123 2
102 1
Case 4: 2 999
NA ----------------------------------------------------------------------------------
思路:题意很清晰,题解见代码。本题最后两个数据点有超时风险,AC需要以下几个优化小技巧。 1.自定义排序引用传参较快
2.string使用printf输出,string.c_str()
3.使用unordered_map(key未排序)优于map,较低版本编译器可能会出现编译错误(c++11)
ps:也可以使用数组变量记录,map虽然只会遍历大于0的key,但效率远不及数组变量
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; struct Node{
string num;
int sco;
}a[],b[]; bool cmp(const Node &a,const Node &b){ //引用传参
if(a.sco==b.sco) return a.num<b.num;
return a.sco>b.sco;
}
int main()
{
int n,m,i,j;
scanf("%d%d",&n,&m);
for(i=;i<=n;i++){
cin>>a[i].num>>a[i].sco;
}
int tt=;
int x;
string y;
while(m--){
tt++;
cin>>x>>y;
printf("Case %d: %d %s\n",tt,x,y.c_str()); //printf输出string
int c=,ans=;
unordered_map<string,int> bb; //c++11版,优于map
for(i=;i<=n;i++){
if(x==){
if(a[i].num[]==y[]){
c++;
b[c].num=a[i].num;
b[c].sco=a[i].sco;
}
}
else if(x==){
if(a[i].num.substr(,)==y){
c++;
ans+=a[i].sco;
}
}
else{
if(a[i].num.substr(,)!=y) continue;
bb[a[i].num.substr(,)]++;
}
}
if(x==){
if(c==) printf("NA\n");
else{
sort(b+,b+c+,cmp);
for(i=;i<=c;i++){
printf("%s %d\n",b[i].num.c_str(),b[i].sco); //
}
}
}
else if(x==){
if(c==) printf("NA\n");
else printf("%d %d\n",c,ans);
}
else{
unordered_map<string,int>::iterator it;
for(it=bb.begin();it!=bb.end();it++){ //只遍历value不为0的key
c++;
b[c].num=it->first;
b[c].sco=it->second;
}
if(c==) printf("NA\n");
else{
sort(b+,b+c+,cmp);
for(i=;i<=c;i++){
printf("%s %d\n",b[i].num.c_str(),b[i].sco); //
}
}
}
}
return ;
}
 

PAT甲 1095 解码PAT准考证/1153 Decode Registration Card of PAT(优化技巧)的更多相关文章

  1. 1153 Decode Registration Card of PAT (25 分)

    A registration card number of PAT consists of 4 parts: the 1st letter represents the test level, nam ...

  2. PAT Advanced 1153 Decode Registration Card of PAT (25 分)

    A registration card number of PAT consists of 4 parts: the 1st letter represents the test level, nam ...

  3. PAT甲级——1153.Decode Registration Card of PAT(25分)

    A registration card number of PAT consists of 4 parts: the 1st letter represents the test level, nam ...

  4. 1153 Decode Registration Card of PAT

    A registration card number of PAT consists of 4 parts: the 1st letter represents the test level, nam ...

  5. PAT_A1153#Decode Registration Card of PAT

    Source: PAT A1153 Decode Registration Card of PAT (25 分) Description: A registration card number of ...

  6. PAT-1153(Decode Registration Card of PAT)+unordered_map的使用+vector的使用+sort条件排序的使用

    Decode Registration Card of PAT PAT-1153 这里需要注意题目的规模,并不需要一开始就存储好所有的满足题意的信息 这里必须使用unordered_map否则会超时 ...

  7. PAT A1153 Decode Registration Card of PAT (25 分)——多种情况排序

    A registration card number of PAT consists of 4 parts: the 1st letter represents the test level, nam ...

  8. PAT Basic 1095 解码PAT准考证 (25 分)

    PAT 准考证号由 4 部分组成: 第 1 位是级别,即 T 代表顶级:A 代表甲级:B 代表乙级: 第 2~4 位是考场编号,范围从 101 到 999: 第 5~10 位是考试日期,格式为年.月. ...

  9. PAT甲级1095. Cars on Campus

    PAT甲级1095. Cars on Campus 题意: 浙江大学有6个校区和很多门.从每个门口,我们可以收集穿过大门的汽车的进/出时间和车牌号码.现在有了所有的信息,你应该在任何特定的时间点告诉在 ...

随机推荐

  1. Java 虚拟机-Java内存区域

    简要介绍Java的内存区域: 运行时数据区域 HotSpot虚拟机对象 一.概览 二.运行时数据区域 2.1 程序计数器 Program Counter Register,代表当前线程所执行的字节码的 ...

  2. LOJ 10189 仓库建设 ——斜率优化dp

    题目:https://loj.ac/problem/10189 #include<iostream> #include<cstdio> #include<cstring& ...

  3. TLD视觉跟踪算法

    TLD算法好牛逼一个,这里有个视频,是作者展示算法的效果,http://www.56.com/u83/v_NTk3Mzc1NTI.html.下面这个csdn博客里有人做的相关总结,感觉挺好的,收藏了! ...

  4. 通过扫码自定义链接安装iOS app,版本更新总结。

    1.打包ipa,plist工具:xcode6证书:企业级开发证书 1.1)xcode6开始企业级打包时不在生成plist,需要自己编写:模版见下: <?xml version="1.0 ...

  5. Boost.Asio基本原理(CSDN也有Markdown了,好开森)

    Boost.Asio基本原理 这一章涵盖了使用Boost.Asio时必须知道的一些事情.我们也将深入研究比同步编程更复杂.更有乐趣的异步编程. 网络API 这一部分包含了当使用Boost.Asio编写 ...

  6. Git 之Windows环境下学习系列

    Git .SVN .TFS   相同点 不同点 Git     版本控制 优点: 分布式版本控制.无需联网就能版本提交 开源 缺点 入门学习难度高 SVN   优点: 集中式版本控制. 个人开源 缺点 ...

  7. vue axios 应用

    vue安装axios cnpm install axios 安装成功后/项目/node_modules/目录下有axios文件夹 在package.json文件中devDependencies字段中添 ...

  8. 解决springMVC文件上传报错: The current request is not a multipart request

    转自:https://blog.csdn.net/HaHa_Sir/article/details/79131607 解决springMVC文件上传报错: The current request is ...

  9. 部署和调优 1.5 vsftp部署和优化-1

    系统自带的ftp服务软件.vsftpd 安装vsftpd yum install -y vsftpd 启动vsftpd /etc/init.d/vsftpd start 如果启动失败,可能是端口被占用 ...

  10. bitcode编译错误

    xcode编译引用的静态库可能会出现编译错误: does not contain bitcode. You must rebuild it with bitcode enabled (Xcode se ...