Source:

PAT A1153 Decode Registration Card of PAT (25 分)

Description:

A registration card number of PAT consists of 4 parts:

  • the 1st letter represents the test level, namely, T for the top level, A for advance and B for basic;
  • the 2nd - 4th digits are the test site number, ranged from 101 to 999;
  • the 5th - 10th digits give the test date, in the form of yymmdd;
  • finally the 11th - 13th digits are the testee's number, ranged from 000 to 999.

Now given a set of registration card numbers and the scores of the card owners, you are supposed to output the various statistics according to the given queries.

Input Specification:

Each input file contains one test case. For each case, the first line gives two positive integers N (≤) and M (≤), the numbers of cards and the queries, respectively.

Then N lines follow, each gives a card number and the owner's score (integer in [), separated by a space.

After the info of testees, there are M lines, each gives a query in the format Type Term, where

  • Type being 1 means to output all the testees on a given level, in non-increasing order of their scores. The corresponding Term will be the letter which specifies the level;
  • Type being 2 means to output the total number of testees together with their total scores in a given site. The corresponding Term will then be the site number;
  • Type being 3 means to output the total number of testees of every site for a given test date. The corresponding Term will then be the date, given in the same format as in the registration card.

Output Specification:

For each query, first print in a line Case #: input, where # is the index of the query case, starting from 1; and input is a copy of the corresponding input query. Then output as requested:

  • for a type 1 query, the output format is the same as in input, that is, CardNumber Score. If there is a tie of the scores, output in increasing alphabetical order of their card numbers (uniqueness of the card numbers is guaranteed);
  • for a type 2 query, output in the format Nt Ns where Nt is the total number of testees and Ns is their total score;
  • for a type 3 query, output in the format Site Nt where Site is the site number and Nt is the total number of testees at Site. The output must be in non-increasing order of Nt's, or in increasing order of site numbers if there is a tie of Nt.

If the result of a query is empty, simply print NA.

Sample Input:

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

Sample Output:

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

Keys:

  • map(C++ STL)
  • string(C++ STL)
  • 快乐模拟

Attention:

  • 每轮mp要记得清空-,-
  • cmp引用传参效率更快
  • cout 输出会超时

Code:

 /*
Data: 2019-08-02 21:39:05
Problem: PAT_A1153#Decode Registration Card of PAT
AC: 34:30 题目大意:
第一行:给出卡片数量n<=1e4,和查询数量m<=100
接下来n行,给出卡号,成绩[0,100]
接下来m行,给出查询
1. 给出指定等级,输出各个考生,及其成绩,递减,卡号递增
2. 给出指定地点,输出考生总数,及其总分,
3. 给出指定时间,输出各个考场的考生总数,人数递减,地点递增
4. 查询失败输出NA
*/
#include<cstdio>
#include<map>
#include<string>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
const int M=1e4+;
struct node
{
string id;
int score;
}info[M]; bool cmp(const node &a, const node &b)
{
if(a.score != b.score)
return a.score > b.score;
else
return a.id < b.id;
} void Query(int k, int n)
{
int index,sum=,cnt=;
string s;
cin >> index >> s;
printf("Case %d: %d %s\n", k,index,s.c_str());
vector<node> ans;
map<string,int> mp;
for(int i=; i<n; i++)
{
if(index== && info[i].id[]==s[])
ans.push_back(info[i]);
else if(index== && info[i].id.substr(,)==s)
{
cnt++;
sum += info[i].score;
}
else if(index== && info[i].id.substr(,)==s)
mp[info[i].id.substr(,)]++;
}
if(index== && cnt!=)
printf("%d %d\n", cnt, sum);
else
for(auto it=mp.begin(); it!=mp.end(); it++)
ans.push_back({it->first,it->second});
sort(ans.begin(),ans.end(),cmp);
for(int i=; i<ans.size(); i++)
printf("%s %d\n", ans[i].id.c_str(),ans[i].score);
if(ans.size()== && cnt==)
printf("NA\n"); return;
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n,m;
scanf("%d%d", &n,&m);
for(int i=; i<n; i++)
cin >> info[i].id >> info[i].score;
for(int i=; i<=m; i++)
Query(i,n); return ;
}

PAT_A1153#Decode Registration Card of PAT的更多相关文章

  1. PAT甲 1095 解码PAT准考证/1153 Decode Registration Card of PAT(优化技巧)

    1095 解码PAT准考证/1153 Decode Registration Card of PAT(25 分) PAT 准考证号由 4 部分组成: 第 1 位是级别,即 T 代表顶级:A 代表甲级: ...

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

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

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 1153 Decode Registration Card of PAT

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

  8. PAT (Advanced Level) Practice(更新中)

    Source: PAT (Advanced Level) Practice Reference: [1]胡凡,曾磊.算法笔记[M].机械工业出版社.2016.7 Outline: 基础数据结构: 线性 ...

  9. PAT(甲级)2018年冬季考试

    1152 Google Recruitment 思路:判断素数 #include<bits/stdc++.h> using namespace std; const int maxn = ...

随机推荐

  1. 【ACM】hdu_zs3_1008_Train Problem I_201308100835

    Train Problem I Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)Tota ...

  2. PHP中echo和print的区别

    这篇文章主要介绍了PHP中echo和print的区别,针对二者使用中常见的用法区别进行了较为深入的总结与分析,需要的朋友可以参考下 一般来说,PHP中动态输出HTML内容,是通过print 和 ech ...

  3. BZOJ 1492 货币兑换 cdq分治或平衡树维护凸包

    题意:链接 方法:cdq分治或平衡树维护凸包 解析: 这道题我拒绝写平衡树的题解,我仅仅想说splay不要写挂,insert边界条件不要忘.del点的时候不要脑抽d错.有想写平衡树的去看140142或 ...

  4. 架构师速成5.1-小学gtd进阶

    人生没有理想,那和咸鱼有什么差别. 有了理想怎样去实现.这就是gtd须要解决的问题.简单说一下gtd怎么做? 确定你的目标.假设不能确定长期目标,至少须要一个2年到3年的目标. 目标必须是能够衡量的, ...

  5. sharepoint类型转换

    sharepoint学习汇总 http://blog.csdn.net/qq873113580/article/details/20390149 r[col.ColumnName] = GetType ...

  6. mongodb 对内存的占用监控 ——mongostat,linux系统可用的内存是free + buffers + cached

    刚开始使用mongodb的时候,不太注意mongodb的内存使用,但通过查资料发现mongodb对内存的占用是巨大的,在本地测试服务器中,8G的内存居然被占用了45%.汗呀. 本文就来剖析一下mong ...

  7. 原生JS---1

    js的历史 在上个世纪的1995年,当时的网景公司正凭借其Navigator浏览器成为Web时代开启时最著名的第一代互联网公司. 由于网景公司希望能在静态HTML页面上添加一些动态效果,于是叫Bren ...

  8. 数据通讯与网络 第五版第24章 传输层协议-UDP协议部分要点

    24.1 介绍 本章节主要集中于传输层协议的解读,图24.1展示TCP.UDP.SCTP在TCP\IP协议栈的位置 24.1.1 服务(Service) 每个协议都提供不同的服务,所以应该合理正确的使 ...

  9. 2019手机号码JS正则表达式

    前端的正则表达式验证往往是最繁多最复杂的,所以整理了一些最近自己常用的正则表达式,希望能对大家有所帮助! /* 合法uri */ export function validateURL(textval ...

  10. CALayer(一)

    CALayer CALayer和UIView CALayer和UIView相比--CALayer少了事件处理的功能,所以更加轻量级,性能更好一点,这就说明如果有一些和用户交互的东西是不建议用CALay ...