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
类型1和2都好处理,就是3需要map,直接记录考场号和日期拼接字符串对应考生的个数,然后排序。
代码:
#include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <map>
#define MAX 10001
using namespace std;
int n,m;
struct stu {
char Tid[];
int score;
}s[MAX];
char *Substr(char *a,int l,int r) {
char *t = (char *)malloc(sizeof(char) * (r - l + ));
for(int i = l;i < r;i ++) {
t[i - l] = a[i];
}
t[r - l] = ;
return t;
}
int snum[],sscore[];///考场对应考生人数 和 总分的数组
int lnum[];
char *str[MAX];///记录考场和日期总串
int c;
map<string,int> mp;
bool cmp(const stu &a,const stu &b) {
if(a.Tid[] == b.Tid[]) {
if(a.score == b.score) return strcmp(a.Tid,b.Tid) < ;
return a.score > b.score;
}
return a.Tid[] < b.Tid[];
}
bool cmp1(const char *a,const char *b) {
if(mp[a] == mp[b]) return strcmp(a,b) < ;
return mp[a] > mp[b];
}
int main() {
char *t;
scanf("%d%d",&n,&m);
for(int i = ;i < n;i ++) {
scanf("%s %d",s[i].Tid,&s[i].score);
t = Substr(s[i].Tid,,);
int d = atoi(t);
snum[d] ++;
sscore[d] += s[i].score;
int dd = s[i].Tid[] == 'T' ? : s[i].Tid[] - 'A';
lnum[dd] ++;
t = Substr(s[i].Tid,,);
if(!mp[t]) {
str[c] = (char *)malloc(sizeof(char) * );
strcpy(str[c],t);
c ++;
}
mp[t] ++;
}
sort(s,s + n,cmp);
sort(str,str + c,cmp1);
int choice,site;
char level[],date[];
for(int i = ;i <= m;i ++) {
scanf("%d",&choice);
printf("Case %d: %d ",i,choice);
if(choice == ) {
scanf("%s",level);
printf("%s\n",level);
int l,r;
if(level[] == 'A') l = ,r = lnum[];
else if(level[] == 'B') l = lnum[],r = lnum[];
else l = lnum[] + lnum[],r = lnum[];
if(r == ) {
printf("NA\n");
continue;
}
for(int j = ;j < r;j ++) {
printf("%s %d\n",s[l + j].Tid,s[l + j].score);
}
}
else if(choice == ) {
scanf("%d",&site);
printf("%d\n",site);
if(!snum[site]) {
printf("NA\n");
}
else {
printf("%d %d\n",snum[site],sscore[site]);
}
}
else {
scanf("%s",&date);
printf("%s\n",date);
int d = ;
for(int j = ;j < c;j ++) {
if(strcmp(Substr(str[j],,),date) == ) {
printf("%s %d\n",Substr(str[j],,),mp[str[j]]);
d ++;
}
}
if(d == ) printf("NA\n");
}
}
}

1153 Decode Registration Card of PAT (25 分)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. PAT甲 1095 解码PAT准考证/1153 Decode Registration Card of PAT(优化技巧)

    1095 解码PAT准考证/1153 Decode Registration Card of PAT(25 分) PAT 准考证号由 4 部分组成: 第 1 位是级别,即 T 代表顶级:A 代表甲级: ...

  4. 1153 Decode Registration Card of PAT

    A registration card number of PAT consists of 4 parts: the 1st letter represents the test level, nam ...

  5. PAT_A1153#Decode Registration Card of PAT

    Source: PAT A1153 Decode Registration Card of PAT (25 分) Description: A registration card number of ...

  6. PAT-1153(Decode Registration Card of PAT)+unordered_map的使用+vector的使用+sort条件排序的使用

    Decode Registration Card of PAT PAT-1153 这里需要注意题目的规模,并不需要一开始就存储好所有的满足题意的信息 这里必须使用unordered_map否则会超时 ...

  7. 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 ...

  8. 1040 有几个PAT (25 分)

    题目:1040 有几个PAT (25 分) 思路: 是个规律题,只要找到规律就有思路,那代码基本就有了,就是怎么实现比较好和是否简洁的问题. 很明显:A是分水岭,A前面有多少个P和A后面有多少个T知道 ...

  9. PAT Basic 1040 有几个PAT (25 分)

    字符串 APPAPT 中包含了两个单词 PAT,其中第一个 PAT 是第 2 位(P),第 4 位(A),第 6 位(T):第二个 PAT 是第 3 位(P),第 4 位(A),第 6 位(T). 现 ...

随机推荐

  1. identityHashCode与偏向锁

    hashCode 我们知道在Java中,一切对象都继承自java.lang.Object类.这个类中有一个可继承的方法叫hashCode().它在Object类中的方法签名是这样的: public n ...

  2. 前端要不要学数据结构&算法

    我们都知道前端开发工程师更多偏向 DOM 渲染和 DOM 交互操作,随之 Node 的推广前端工程师也可以完成服务端开发.对于服务端开发而言大家都觉得数据结构和算法是基础,非学不可.所以正在进行 No ...

  3. 【Python】学习笔记之列表生成式

    列表生成式 主要用于生成较为复杂的列表 常用用法 >>> [x * x for x in range(5) if x % 3 !=1 ] [0, 4, 9] #返回除以3余数不为1的 ...

  4. PHP运算符-算术运算符、三元运算符、逻辑运算符

    运算符是用来对变量.常量或数据进行计算的符号,它对一个值或一组值执行一个指定的操作.PHP的运算符包括算术运算符.字符串运算符.赋值运算符.位运算符.逻辑运算符.比较运算符.递增或递减运算符.错误控制 ...

  5. go-statsd项目

    linux命令: 进程:top 收包丢包:netstat -su[c持续输出] go tool pprof: 我们可以使用go tool pprof命令来交互式的访问概要文件的内容.命令将会分析指定的 ...

  6. spring mvc: 生成RSS源

    spring mvc: 生成RSS源 准备: 从相同的maven存储库页面下载 Rome 库及其依赖项rome-utils,jdom和slf4j.和所需的依赖关系 <!-- rss源依赖 --& ...

  7. yii2打印数据属性(字段名)/数据

    yii2打印数据属性(字段名)/数据 单条数据: $model = $this->findModel($id);//打印字段名 $array = $model->attributes(); ...

  8. C++双向循环链表实现

    双向循环链表C++实现 1.单链表: 结构图: 2.双向链表: 3.双向循环链表: 对于本程序中,则是给定一个_head  头结点,而不是指针,因为这样更加方便避免一些空判断问题 /* 版权信息:狼 ...

  9. echarts 折线图配置

    html内容: <div id="user_num_chart" style="width: 582px;height:250px;"></d ...

  10. Quartz 框架 教程(中文版)2.2.x

    Quartz 框架 教程(中文版)2.2.x 之第一课 开始使用Quartz框架 Quartz 框架 教程(中文版)2.2.x 之第二课 Quartz API,Jobs和Triggers简介 Quar ...