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 ...
随机推荐
- 面试题:实现strcpy,strlen,strcmp,strcat,memcpy 之c-style字符串
哪里可以看到c库函数的源码? gnu的c运行库glibc,但是源码的实现却是复杂的,需要考虑效率,stlen源码分析. c-style字符串有个约定,以空字符结尾,即 '\0' . ' }; &quo ...
- (转)关于SimpleDateFormat安全的时间格式化线程安全问题
想必大家对SimpleDateFormat并不陌生.SimpleDateFormat 是 Java 中一个非常常用的类,该类用来对日期字符串进行解析和格式化输出,但如果使用不小心会导致非常微妙和难以调 ...
- 阿里巴巴高级Java面试题(首发,70道)
整理的70道阿里的Java面试题,都来挑战一下,看看自己有多厉害.下面题目都带超详细的解答,详情见底部. 1.java事件机制包括哪三个部分?分别介绍. 2.为什么要使用线程池? 3.线程池有什么作用 ...
- springCloud的使用09-----高可用的注册中心
思路:创建多个注册中心,在他们的配置文件中配置相互之间的注册 1 在eureka-server项目的resources目录下创建两个配置文件application-peer1.yml和applicat ...
- Codeforces 500C New Year Book Reading
C. New Year Book Reading time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Python基础篇(格式化输出,运算符,编码):
Python基础篇(格式化输出,运算符,编码): 格式化输出: 格式:print ( " 内容%s" %(变量)) 字符类型: %s 替换字符串 %d 替换整体数字 ...
- Jquery查找界面Html元素的方法(持续更新)
1. 根据id来获取:$("#id") 2.根据class来获取:$(".class") 3.根据name来获取:$("[name=??]" ...
- C#编程--第二天
一.变量:变量先声明,后赋值,再使用. 语法:变量类型 变量名=值: 变量类型: 分为基本数据类型和引用类 基本数据类型:整型.浮点型.字符型.布尔型 引用类:字符串.日期时间.枚举类型.结构类型 i ...
- Chocolatey Window系统下的软件管理工具
前言: 使用linux都喜欢使用yum ;apt-get来安装包,非常方便,那么windows也可以使用这样的方式. Chocolatey软件是Windows下的软件安装工具: 使用方法类似linux ...
- 查看linux 用户登录信息及ip
查看可疑IP登陆 last -f /var/log/wtmp cat /var/log/secure 寻找可疑ip登陆次数及信息 who 查看当前登陆用户 -h 忽略头文件信息 -u 显示结 ...