PAT_A1153#Decode Registration Card of PAT
Source:
Description:
A registration card number of PAT consists of 4 parts:
- the 1st letter represents the test level, namely,
 Tfor the top level,Afor advance andBfor 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
Typebeing 1 means to output all the testees on a given level, in non-increasing order of their scores. The correspondingTermwill be the letter which specifies the level;Typebeing 2 means to output the total number of testees together with their total scores in a given site. The correspondingTermwill then be the site number;Typebeing 3 means to output the total number of testees of every site for a given test date. The correspondingTermwill 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; andinputis 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 NswhereNtis the total number of testees andNsis their total score;- for a type 3 query, output in the format
 Site NtwhereSiteis the site number andNtis the total number of testees atSite. The output must be in non-increasing order ofNt's, or in increasing order of site numbers if there is a tie ofNt.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的更多相关文章
- PAT甲 1095 解码PAT准考证/1153 Decode Registration Card of PAT(优化技巧)
		
1095 解码PAT准考证/1153 Decode Registration Card of PAT(25 分) PAT 准考证号由 4 部分组成: 第 1 位是级别,即 T 代表顶级:A 代表甲级: ...
 - PAT-1153(Decode Registration Card of PAT)+unordered_map的使用+vector的使用+sort条件排序的使用
		
Decode Registration Card of PAT PAT-1153 这里需要注意题目的规模,并不需要一开始就存储好所有的满足题意的信息 这里必须使用unordered_map否则会超时 ...
 - 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 ...
 - 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 ...
 - 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 ...
 - 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 ...
 - 1153 Decode Registration Card of PAT
		
A registration card number of PAT consists of 4 parts: the 1st letter represents the test level, nam ...
 - PAT (Advanced Level) Practice(更新中)
		
Source: PAT (Advanced Level) Practice Reference: [1]胡凡,曾磊.算法笔记[M].机械工业出版社.2016.7 Outline: 基础数据结构: 线性 ...
 - PAT(甲级)2018年冬季考试
		
1152 Google Recruitment 思路:判断素数 #include<bits/stdc++.h> using namespace std; const int maxn = ...
 
随机推荐
- 数学 找规律 Jzzhu and Sequences
			
A - Jzzhu and Sequences Jzzhu has invented a kind of sequences, they meet the following property: ...
 - Colored Sticks (并查集+Trie + 欧拉路)
			
Time Limit: 5000MS Memory Limit: 128000K Total Submissions: 37340 Accepted: 9796 Description You ...
 - Android 中View的绘制机制源代码分析 一
			
尊重原创: http://blog.csdn.net/yuanzeyao/article/details/46765113 差点儿相同半年没有写博客了,一是由于工作比較忙,二是认为没有什么内容值得写, ...
 - gitserver提交代码的总结
			
将更新的代码提交到gitserver上所须要的步骤: 1.git pull 更新代码到最新 2,git add 文件名称 加入要提交的文件 3,git commit -m "关于改动的内 ...
 - 架构师速成5.1-小学gtd进阶
			
人生没有理想,那和咸鱼有什么差别. 有了理想怎样去实现.这就是gtd须要解决的问题.简单说一下gtd怎么做? 确定你的目标.假设不能确定长期目标,至少须要一个2年到3年的目标. 目标必须是能够衡量的, ...
 - windows server使用 LetsEncrypt-Win-Simple来安装和使用用Let's Encrypt免费SSL证书
			
一.网站部署 LetsEncrypt-Win-Simple可以自动发现已经部署的网站供我们选择要生成证书的网站,而且还需要进行验证.所以在生成证书之前,确保网站已经部署好并可以正常访问. 二.生成证书 ...
 - uboot向内核模块传递参数的方法
			
1 模块参数 定义模块参数 1 module_param(name, type, perm); 定义一个模块参数, name 变量名 type 数据类型 bool:布尔型 invbool:一个布尔型( ...
 - Linux I2C驱动分析(三)----i2c_dev驱动和应用层分析 【转】
			
本文转载自:http://blog.chinaunix.net/uid-21558711-id-3959287.html 分类: LINUX 原文地址:Linux I2C驱动分析(三)----i2c_ ...
 - OST
			
爱情的条件 http://music.163.com/#/album?id=531414 kill me heal me http://music.163.com/#/album?id=3104890
 - 【BZOJ 1601】 灌水
			
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1601 [算法] 最小生成树 [代码] #include<bits/stdc++ ...