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. jquery-radio 事件监听以及取值

    $("input:radio[name='ssx']").change(function (){ alert( $(this).val()); alert($("inpu ...

  2. Spring MVC-集成(Integration)-生成JSON示例(转载实践)

    以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_json.htm 说明:示例基于Spring MVC 4.1.6. 以下示例显示如 ...

  3. HDU 5241 上海大都会 F题

    留意到,每一种语言的情况其实是独立的,也就是说,每一种语言的集合的包含的情况都是符合要求的.一种语言在图上可以有32种情况(由数据2知),所以,总的数就是32^n import java.util.* ...

  4. tiny4412移植opencv2.4.7手记

    在买了新的4412板子后.打算趁着刚成功在6410上移植过的经验,速度解决下.不想出现了各种问题.小结下: 1.关于opencv的移植: tiny4412的linux3.5上,须要把opencv的li ...

  5. WPF中控件TextBlock使用(简单)

    TextBlock主要用来显示文字.比方: <TextBlock Name="txtBlockOutpuMessage"   Text="hello" / ...

  6. java调用c++ dll出现中文乱码

    近期的开发用到了使用java调用本机动态连接库的功能,将文件路径通过java调用C++代码对文件进行操作. 在调用中假设路径中包括有中文字符就会出现故障.程序执行就会中止. 以下用一个小样例,来说明记 ...

  7. Recovery 中的UI知识积累【转】

    本文转载自:http://blog.csdn.net/wed110/article/details/26554197 int gr_init(void);             /* 初始化图形显示 ...

  8. poj 3662 Telephone Lines(最短路+二分)

    Telephone Lines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6973   Accepted: 2554 D ...

  9. 关于逆元&&lucas定理

    lucas是求组合数C(m,n)%p,有一个公式:C(m,n) = C(m/p,n/p)*C(m%p,n%p). (a*b)%c==a%c*b%c,但是(a/b)%c!=a%c/b%c,所以我们要算b ...

  10. 洛谷 P3953 [ NOIP 2017 ] 逛公园 —— 最短路DP

    题目:https://www.luogu.org/problemnew/show/P3953 主要是看题解...还是觉得好难想啊... dfs DP,剩余容量的损耗是边权减去两点最短路差值...表示对 ...