1153 Decode Registration Card of PAT (25 分)
A registration card number of PAT consists of 4 parts:
- the 1st letter represents the test level, namely,
Tfor the top level,Afor advance andBfor 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
Typebeing 1 means to output all the testees on a given level, in non-increasing order of their scores. The correspondingTermwill be the letter which specifies the level;Typebeing 2 means to output the total number of testees together with their total scores in a given site. The correspondingTermwill then be the site number;Typebeing 3 means to output the total number of testees of every site for a given test date. The correspondingTermwill 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 NswhereNtis the total number of testees andNsis their total score; - for a type 3 query, output in the format
Site NtwhereSiteis the site number andNtis 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类型1和2都好处理,就是3需要map,直接记录考场号和日期拼接字符串对应考生的个数,然后排序。
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
代码:
#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 分)的更多相关文章
- 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 ...
- 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 ...
- PAT甲 1095 解码PAT准考证/1153 Decode Registration Card of PAT(优化技巧)
1095 解码PAT准考证/1153 Decode Registration Card of PAT(25 分) PAT 准考证号由 4 部分组成: 第 1 位是级别,即 T 代表顶级:A 代表甲级: ...
- 1153 Decode Registration Card of PAT
A registration card number of PAT consists of 4 parts: the 1st letter represents the test level, nam ...
- PAT_A1153#Decode Registration Card of PAT
Source: PAT A1153 Decode Registration Card of PAT (25 分) Description: A registration card number of ...
- PAT-1153(Decode Registration Card of PAT)+unordered_map的使用+vector的使用+sort条件排序的使用
Decode Registration Card of PAT PAT-1153 这里需要注意题目的规模,并不需要一开始就存储好所有的满足题意的信息 这里必须使用unordered_map否则会超时 ...
- 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 ...
- 1040 有几个PAT (25 分)
题目:1040 有几个PAT (25 分) 思路: 是个规律题,只要找到规律就有思路,那代码基本就有了,就是怎么实现比较好和是否简洁的问题. 很明显:A是分水岭,A前面有多少个P和A后面有多少个T知道 ...
- PAT Basic 1040 有几个PAT (25 分)
字符串 APPAPT 中包含了两个单词 PAT,其中第一个 PAT 是第 2 位(P),第 4 位(A),第 6 位(T):第二个 PAT 是第 3 位(P),第 4 位(A),第 6 位(T). 现 ...
随机推荐
- less文件的运行
例:在任意处创建一个.less文件,比如在桌面2017.06.28文件中创建了一个main.less文件,然后通过命令行编译main.less,步骤: win+R,cmd打开命令面板,切换到main. ...
- 在线前端开发平台 Plunker
Plunker 网站 : http://plnkr.co/ Plunker 是一个用来创建.协作和分享 Web 开发思路的在线社区.编辑界面如下图所示: 特点: 基于 Node.js 环境运行 实时的 ...
- [postgresql]ROWS is not applicable when function does not return a set问题解决
需要把程序结尾的ROWS 1000去掉,提示如果函数不是返回一个数据集的情况下ROWS是不适用的: CREATE OR REPLACE FUNCTION public.function( eigyou ...
- 【Demo】jQuery 可编辑表格
功能实现: (1)设定单元格的单击事件,判定被单击单元格是否已经是可编辑状态: (2)取出单元格原有内容,想单元格中加入文本框,并把原有内容显示在文本框中: (3)当用户编辑完成或者取消编辑后,将文本 ...
- 25.大白话说java并发工具类-CountDownLatch,CyclicBarrier,Semaphore,Exchanger
1. 倒计时器CountDownLatch 在多线程协作完成业务功能时,有时候需要等待其他多个线程完成任务之后,主线程才能继续往下执行业务功能,在这种的业务场景下,通常可以使用Thread类的join ...
- 身份证真实性校验js、mini ui身份证长度正则验证
身份证号码真实性校验 <input type="text" value="请输入身份证号" id="cards" ><bu ...
- echarts 折线图配置
html内容: <div id="user_num_chart" style="width: 582px;height:250px;"></d ...
- 控制语句2:循环:for 与 while
循环是所有编程语言的必备利器,用于重复的动作等等. python中的循环有何特殊性:for 与 while 都有自己的else分支. 要学会刹车: 1.条件的控制次数 2.break 与 contin ...
- Java复习10.Servlet编程
Java复习10. Servlet编程知识 20131008 前言: 之前在大三下的时候,学习了一个月的JSP和Servlet知识,但是没有什么项目经验,把JSP Web开发学习实录看了前面几张,后面 ...
- JBPM4入门——2.在eclipse中安装绘制jbpm流程图的插件
本博文只是简要对JBPM4进行介绍,如需更详细内容请自行google 链接: JBPM入门系列文章: JBPM4入门——1.jbpm简要介绍 JBPM4入门——2.在eclipse中安装绘制jbpm流 ...