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. 在lnmp下开启fileinfo扩展 Ubuntu系统

    在lnmp下开启fileinfo扩展 Ubuntu系统 1.进入目录下 cd /usr/local/lnmp1.4-full/src/php-5.6.31/ext/fileinfo 2.phpize处 ...

  2. (转)SQL一次性插入大量数据

    在SQL Server 中插入一条数据使用Insert语句,但是如果想要批量插入一堆数据的话,循环使用Insert不仅效率低,而且会导致SQL一系统性能问题.下面介绍SQL Server支持的两种批量 ...

  3. 使用IDEA创建SpringBoot自定义注解

    创建SpringBoot项目 添加组织名 选择web 输入项目名称 创建后目录结构为 使用Spring的AOP先加入Maven依赖 <dependency> <groupId> ...

  4. java MongoDB查询(二)复杂查询

    前言 在上篇<java MongoDB查询(一)简单查询>中我们简单了解了下查询,但是仅仅有那些查询是不够用的,还需要复杂的查询,这篇就这点进行叙述. 1.数据结构 集合:firstCol ...

  5. canvas图形的组合与裁切

    当两个或两个以上的图形存在重叠区域时,默认情况下一个图形画在前一个图像之上.通过指定图像globalCompositeOperation属性的值可以改变图形的绘制顺序或绘制方式,globalAlpha ...

  6. web前端 —— 移动端知识的一些总结

    个人在移动端的一些总结归纳,有新的知识点会一直更新 一.css部分 1.meta标签 <meta name="viewport" content="width=de ...

  7. es6 nodejs compose

    const compose = (...fns) => { let len = fns.length; let fn_index = len - 1; let fn_result; functi ...

  8. 010PHP基础知识——运算符(三)

    <?php /** * 位运算符: * 1:&按位与:左右两边的数,同位都为1,返回是1,否则返回是0 */ /*$a = 5; $b = 6; $a = decbin($a);//10 ...

  9. lvs fullnat部署手册(一)fullnat内核编译篇

    标签:kernel rpm lvs fullnat 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://shanks.blog.51c ...

  10. SCM-MANAGER-禁用用户

    用管理远用户登录到scm-manager的管理界面http://*.*.*.*:8081/ 设置目标用户为禁用 验证 非 “active” 状态 目标用户客户端不能pull 一直提示登录