PAT甲级——A1153 DecodeRegistrationCardofPAT【25】
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; 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 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
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 ...
随机推荐
- CRF条件随机场在机器视觉中的解释
CRF是一种判别模型,本质是给定观察值集合的马尔科夫随机场(MRF),而MRF是加了马尔科夫性质限制的随机场. 马尔科夫性质:全局.局部.成对 随机场:看做一组随机变量的集合(对应于同一个样本空间), ...
- Vue2.0---webpack打包知识点-2
先贴一篇对vue-cli#2.0进行webpack配置的详细分析: https://zhuanlan.zhihu.com/p/24322005 一.看一下webpack的打包流程 1.package. ...
- 使用UI Automation实现自动化测试--5-7
使用UI Automation实现自动化测试--5 (Winfrom和WPF中弹出和关闭对话框的不同处理方式) 在使用UI Automation对Winform和WPF的程序测试中发现有一些不同的地方 ...
- jquery 的几种写法和常见问题
为了理解页面初始化事件的编写和执行方式,特此记录下页面加载事件的语句方式: //最简单的加载事件语句 $(function(){ alert("这个提示框最先弹出")//这个用的最 ...
- mysql自带压测工具--mysqlslap
mysqlslap 压测 mysql 5.7.20 目前版本,打印不出内存.cpu使用信息 mysqlslap -h192.168.9.60 -P4406 -uroot -p --create-sc ...
- Java面试之String、StringBuffer和StringBuilder的区别和原理
首先我们先来谈谈String: String 对象一旦创建,其值是不能修改的,如果要修改,会重新开辟内存空间来存储修改之后的对象,即修改了 String 的引用. 因为 String 的底层是用数组来 ...
- hashRouter and BrowserRouter
<html><body> <div> <button class="btn" onclick="btnFun();"& ...
- 三、Centos7安装Mysql
1.到服务器下载的链接 wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm 2.执行命令 sudo r ...
- 如何限制只有某些IP才能使用Tomcat Manager
只有指定的主机或IP地址才可以访问部署在Tomcat下的应用.Tomcat提供了两个参数供你配置:RemoteHostValve 和RemoteAddrValve,前者用于限制主机名,后者用于限制IP ...
- 转载 Tomcat集群配置学习篇-----分布式应用
Tomcat集群配置学习篇-----分布式应用 现目前基于javaWeb开发的应用系统已经比比皆是,尤其是电子商务网站,要想网站发展壮大,那么必然就得能够承受住庞大的网站访问量:大家知道如果服务器访问 ...