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. LeetCode Find Mode in Binary Search Tree

    原题链接在这里:https://leetcode.com/problems/find-mode-in-binary-search-tree/#/description 题目: Given a bina ...

  2. java实现sendemail

    <dependency> <groupId>com.sun.mail</groupId> <artifactId>javax.mail</arti ...

  3. java编程思想第八章多态

    前言: 封装:通过合并特征和行为创建新的数据类型. 实现隐藏:通过将细节“私有化”,把接口和实现分离. 多态:消除类型间的耦合关系.也称作动态绑定,后期绑定或运行时绑定. 8.1再论向上转型: 对象既 ...

  4. boost::ASIO的同步方式和异步方式

    http://blog.csdn.net/zhuky/article/details/5364574 http://blog.csdn.net/zhuky/article/details/536468 ...

  5. 机器学习:scikit-learn 文档、深入学习机器学习的思路

    一.scikit-learn 的文档查阅 网页访问 scikit-learn 的文档: scikit-learn.org —— Document —— User Guide: scikit-learn ...

  6. java代码继承。。。找出不能继承父类方法的问题

    总结:当子类中没有定义name属性时,在子类的无参构造方法中,父类的姓名是不能被继承的. 输出的结果是,子类无参构造方法里的属性值,也就是是属 控制台显示: 我叫:周杰伦,今年:2岁我的姓名:周杰伦, ...

  7. 2011-12-14 调用cmd并获得输入输出+网络访问

    System.Diagnostics.Process pro = new System.Diagnostics.Process(); pro.StartInfo.FileName = "cm ...

  8. HOOK技术演示

    前提:64位系统需要用64位编译dll 一.首先创建一个dll工程,取名为KeyboardHookDll,代码如下: // KeyboardHookDll.cpp : 定义 DLL 应用程序的导出函数 ...

  9. IEEE 2012 PHM数据挑战赛

    Sutrisno E, Oh H, Vasan A S S, et al. Estimation of remaining useful life of ball bearings using dat ...

  10. Android ListView 设置

    android:minHeight="80dip"//设置每一条的高度 android:divider="@null" //设置默认的分割线不显示 androi ...