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,
T
for the top level,A
for advance andB
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 correspondingTerm
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 correspondingTerm
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 correspondingTerm
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; andinput
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
whereNt
is the total number of testees andNs
is their total score;- for a type 3 query, output in the format
Site Nt
whereSite
is the site number andNt
is 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 = ...
随机推荐
- MySQL的各种网络IO超时的用法和实现
2016-04-06 赵伟 数据库开发者 客户端C API 在C API中调用mysql_options()来设置mysql_init() 所创建的连接对象的属性,使用这三个选项可以设置连接超时和读写 ...
- iphone照片查看器
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- stl变易算法(三)
本篇接着前面stl变易算法(一)和stl变易算法(二)继续讲述变易算法. 这里将介绍完余下的变易算法,主要有:填充fill.n次填充fill_n.随机生成元素generate.随机生成n个元素gene ...
- MySql解压版使用
1.解压 2.配置环境变量 3.新建空目录data,修改ini配置文件,修改basedir和datadir 4.管理员运行cmd,进入bin目录 5.mysql -install,如果提示错误,先my ...
- 在Cocos2d-X中玩转精灵
创建一个Cocos2d-Xproject,project的文件夹例如以下图所看到的: 在Resourcees目录中加入一张png格式的图片 在HelloWorldScene.cpp文件里的bool H ...
- HashMap源代码剖析
大部分思路都是一样的 .仅仅是一些细节不一样.源代码中都标了出来.jdk容器源代码还是挺简单的. public class HashMap<K,V> extends AbstractMap ...
- matlab中s函数编写心得-转自水木
S函数是system Function的简称,用它来写自己的simulink模块.(够简单吧,^_^, 详细的概念介绍大伙看帮助吧)可以用matlab.C.C++.Fortran.Ada等语言来写, ...
- B. Sereja and Suffixes(cf)
http://codeforces.com/problemset/problem/368/B B. Sereja and Suffixes time limit per test 1 second m ...
- go之结构体
一.关于结构体 简述 1.go 语言的切片可以存储同一类型的数据,但是结构体可以为不同项定义不同的数据类型 2.结构体是有一系列具有相同类型或不同类型的数据构成的数据集合 3.因为go 没有类似于类的 ...
- SpringCloud 之 Fegin —— 发送GET、POST请求以及文件上传
由于项目需要调用其他微服务的数据,首先想到的就是写一个http网络请求的工具类,但是想到在之前看springCloud的时候里面有这个Fegin可以实现,就顺便实践一下,虽然过程有点坎坷,好在都顺利解 ...