PAT甲级——A1153 DecodeRegistrationCardofPAT【25】
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; 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
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
Solution:
这道题就是简单的进行分类判断
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <algorithm>
using namespace std;
struct node {
string t;
int value;
};
bool cmp(const node &a, const node &b) {
return a.value != b.value ? a.value > b.value : a.t < b.t;
}
int main() {
int n, k, num;
string s;
cin >> n >> k;
vector<node> v(n);
for (int i = ; i < n; i++)
cin >> v[i].t >> v[i].value;
for (int i = ; i <= k; i++) {
cin >> num >> s;
printf("Case %d: %d %s\n", i, num, s.c_str());
vector<node> ans;
int cnt = , sum = ;
if (num == ) {
for (int j = ; j < n; j++)
if (v[j].t[] == s[])
ans.push_back(v[j]);
}
else if (num == ) {
for (int j = ; j < n; j++) {
if (v[j].t.substr(, ) == s) {
cnt++;
sum += v[j].value;
}
}
if (cnt != )
printf("%d %d\n", cnt, sum);
}
else if (num == ) {
unordered_map<string, int> m;
for (int j = ; j < n; j++)
if (v[j].t.substr(, ) == s) m[v[j].t.substr(, )]++;
for (auto it : m)
ans.push_back({ it.first, it.second });
}
sort(ans.begin(), ans.end(), cmp);
for (int j = ; j < ans.size(); j++)
printf("%s %d\n", ans[j].t.c_str(), ans[j].value);
if (((num == || num == ) && ans.size() == ) || (num == && cnt ==
)) printf("NA\n");
}
return ;
}
PAT甲级——A1153 DecodeRegistrationCardofPAT【25】的更多相关文章
- PAT 甲级 1010 Radix (25)(25 分)进制匹配(听说要用二分,历经坎坷,终于AC)
1010 Radix (25)(25 分) Given a pair of positive integers, for example, 6 and 110, can this equation 6 ...
- PAT 甲级1003 Emergency (25)(25 分)(Dikjstra,也可以自己到自己!)
As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...
- pat 甲级 1010. Radix (25)
1010. Radix (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a pair of ...
- pat 甲级 1078. Hashing (25)
1078. Hashing (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The task of t ...
- PAT 甲级 1003. Emergency (25)
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- PAT 甲级 1078 Hashing (25 分)(简单,平方二次探测)
1078 Hashing (25 分) The task of this problem is simple: insert a sequence of distinct positive int ...
- PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)
1070 Mooncake (25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...
- PAT 甲级 1032 Sharing (25 分)(结构体模拟链表,结构体的赋值是深拷贝)
1032 Sharing (25 分) To store English words, one method is to use linked lists and store a word let ...
- PAT 甲级 1029 Median (25 分)(思维题,找两个队列的中位数,没想到)*
1029 Median (25 分) Given an increasing sequence S of N integers, the median is the number at the m ...
随机推荐
- mysql null 值查询问题
我在开发公司内部的一个项目时遇到一个问题:select student_quality_id from STUDENT_QUALITY where mark_status=0 and batch_st ...
- [Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being
[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent c ...
- tomcat开启PID文件
1.配置tomcat启动后将进程号保存至 ./bin/tomcat.pid 文件. 修改 catalina.sh 文件,在 PRGDIR 下面一行添加 CATALINAPID 参数行,如下: PRGD ...
- C++中函数调用操作符的重载
1,本博文讲述函数对象问题: 2,客户需求: 1,编写一个函数: 1,函数可以获得斐波那契数列每项的值: 2,每调用一次返回一个值: 3,函数可根据需要重复使用: 4,代码示例: ; i<; i ...
- 搭建 webpack、react 开发环境(三)
配置 react-router-dom 我们开发一个 React 工程肯定不是一两个“页面”就可以满足需求的,所以我们需要一个在多个“页面”中跳转的功能,在使用 React 构建的单页面应用中,要 ...
- 【笔记目录1】ASP.NET Core分布式项目实战
当前标签: ASP.NET Core分布式项目实战 共2页: 1 2 下一页 35.Docker安装Mysql挂载Host Volume GASA 2019-06-20 22:02 阅读:51 评论 ...
- 最新版的node安装和配置注意事项
node在安装的时候,如果你不想用默认的安装路径,可以自定义路径进行安装,例如我的安装路径如下:F:\Program Files\nodejs 安装完成后,要对node进行配置: 在F:\Progra ...
- 解决 Failed to load class "org.slf4j.impl.StaticLoggerBinder"
我们在使用日志记录网站或者应用时,有时候启动会出现这个告警: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder&q ...
- 一、Nuget管理
一.注册账号 http://www.nuget.org 可用微软账户登录注册 手机端授权 二.打包Nuget 1.新建一个.NET Standard 的类库项目(取名类库) 更改方法 2.选择项目属性 ...
- Ansible--01 ansible基础 Ansible-ad- hoc
目录 自动化运维工具-Ansible基础 自动化运维的含义 Ansible 基础及安装 Ansible的架构 Ansible的执行流程 ansible配置文件 ansible Inventory(主机 ...