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. 用cookies判断用户首次登录

    要求:判断24小时内用户是否是首次登录,如果是则显示弹窗,如果不是则不再显示弹窗 (function() { //是否是新访客 function isNewVisitor() { //从cookie读 ...

  2. stdclass

    $item = new stdClass();      $item->goods_id = $item_goods->getID();      $item->goods_name ...

  3. Vue 及框架响应式系统原理

    个人bolg地址 全局概览 Vue运行内部运行机制 总览图: 初始化及挂载 在 new Vue()之后. Vue 会调用 _init 函数进行初始化,也就是这里的 init 过程,它会初始化生命周期. ...

  4. wget下载指定目录下的文件

    wget -r -np -k -P  ~/tmp/    http://xxx.com/download -P 表示下载到哪个目录-r 表示递归下载-np 表示不下载旁站连接.-k 表示将下载的网页里 ...

  5. [MyEclipse]转:设置注释格式

    Window --> Java --> Code Style --> Code Templates --> Comments --> types --> Edit ...

  6. Reverse a String

    题目: 翻转字符串 先把字符串转化成数组,再借助数组的reverse方法翻转数组顺序,最后把数组转化成字符串. 你的结果必须得是一个字符串 这是一些对你有帮助的资源: Global String Ob ...

  7. 025——VUE中事件的基本使用与VUE中差异

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. java程序设计基础篇 复习笔记 第一单元

    java语言程序设计基础篇笔记1. 几种有名的语言COBOL:商业应用FORTRAN:数学运算BASIC:易学易用Visual Basic,Delphi:图形用户界面C:汇编语言的强大功能和易学性,可 ...

  9. 官方文档-Linux服务器集群系统(一)

    转载-Linux服务器集群系统(一) LVS项目介绍 章文嵩 (wensong@linux-vs.org)2002 年 3 月 本文介绍了Linux服务器集群系统--LVS(Linux Virtual ...

  10. SpringAnnotation注解之@PreDestroy,@PostConstruct,@Scope

    @Scope的使用很简单,直接在类上加上就行 @PostConstruct:相当于xml配置方式的init-method方法 @PreDestroy:相当于xml配置方式的destroy-method ...