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. JS实现的base64加密、md5加密及sha1加密详解

    1.base64加密 在页面中引入base64.js文件,调用方法为: <!DOCTYPE HTML> <html> <head> <meta charset ...

  2. TCP_DB_中间件_遗留问题

    1.一些经验 1.1.Delphi客户端中 Block的socket,使用 读取超时的话,会有大约1秒的时间等待...很影响使用体验...于是 放弃超时读取的方式,改为 在每次读取到TCP数据包时 都 ...

  3. angular指令与指令交互

    app.directive('mansory',function(){ return { controller:function($scope){ this.changed = function(){ ...

  4. HTML5 history API,创造更好的浏览体验

    HTML5 history API有什么用呢? 从Ajax翻页的问题说起 请想象你正在看一个视频下面的评论,在翻到十几页的时候,你发现一个写得稍长,但非常有趣的评论.正当你想要停下滚轮细看的时候,手残 ...

  5. ionic+cordova 学习开发App(一)

    一.项目所需环境 (一)jdk 1.jdk的安装,必须同时包含Java 和javac [一般安装包中都包含有,可以确定下] (二)node.js 和NPM 1.大多插件和辅助工具都运行在NPm平台上. ...

  6. buffer与cache的区别

    top命令中有两项与内存相关的东西:buffer和cache.这两项与页高速缓存相关.磁盘的操作有逻辑级(文件系统)和物理级(磁盘块),这两种Cache就是分别缓存逻辑和物理级数据的. 在linux内 ...

  7. 【Error】IOError: [Errno 22] invalid mode ('wb') or filename

    错误描述: IOError: [Errno 22] invalid mode ('wb') or filename: 'C:\\Users\\Viral Patel\\Documents\\GitHu ...

  8. oracle 修改字符集 修改为ZHS16GBK

    oracle数据库的字符集更改 A.oracle server 端 字符集查询 select userenv('language') from dual 其中NLS_CHARACTERSET 为ser ...

  9. CF 187C Weak Memory 优先队列 难度:2

    http://codeforces.com/problemset/problem/187/C 这道题可以用二分+dfs检测,或者优先队列解 此处用了优先队列解法 从起点出发,维护一个优先队列,内容是p ...

  10. JS中apply与call的用法

    JavaScript中有一个call和apply方法,其作用基本相同,但也有略微的区别. 先来看看JS手册中对call的解释: call 方法调用一个对象的一个方法,以另一个对象替换当前对象. cal ...