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, namely,
T
for the top level,A
for advance andB
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 correspondingTerm
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 correspondingTerm
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 correspondingTerm
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
whereNt
is the total number of testees andNs
is their total score; - for a type 3 query, output in the format
Site Nt
whereSite
is the site number andNt
is 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 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 <unordered_map> #include <algorithm> using namespace std; struct stu{ string num; int grade; }; bool cmp1(const stu& s1,const stu& s2){ if(s1.grade!=s2.grade) return s1.grade>s2.grade; else return s1.num<s2.num; } bool cmp3(const pair<string,int>& p1,const pair<string,int>& p2){ if(p1.second!=p2.second) return p1.second>p2.second; else return p1.first<p2.first; } int main() { int peo,test;stu tmp; int case_num;string case_str; cin>>peo>>test; vector<stu> vec; for(int i=0;i<peo;i++){ cin>>tmp.num>>tmp.grade; vec.push_back(tmp); } for(int i=1;i<=test;i++){ cin>>case_num>>case_str; printf("Case %d: %d %s\n",i,case_num,case_str.data()); if(case_num==1){ vector<stu> vec1; for(int j=0;j<peo;j++){ if(vec[j].num[0]==case_str[0]) vec1.push_back(vec[j]); } sort(vec1.begin(),vec1.end(),cmp1); for(int j=0;j<vec1.size();j++) printf("%s %d\n",vec1[j].num.data(),vec1[j].grade); if(vec1.size()==0) printf("NA\n"); }else if(case_num==2){ int num=0,score=0; for(int j=0;j<peo;j++){ if(vec[j].num.substr(1,3)==case_str){ num++;score+=vec[j].grade; } } if(num==0) printf("NA\n"); else printf("%d %d\n",num,score); }else{ unordered_map<string,int> m; for(int j=0;j<peo;j++){ if(vec[j].num.substr(4,6)==case_str){ m[vec[j].num.substr(1,3)]++; } } vector<pair<string,int>> vec3(m.begin(),m.end()); sort(vec3.begin(),vec3.end(),cmp3); for(int i=0;i<vec3.size();i++) printf("%s %d\n",vec3[i].first.data(),vec3[i].second); if(vec3.size()==0) printf("NA\n"); } } system("pause"); return 0; }
我这边乙级甲级出现了同样的错误,就是这个NA,应该每个都应该打印。
超时,使用unordered_map,如果还是超时,那么把cout换成printf,如果还是超时,那么把cin换成scanf
原文地址:https://www.cnblogs.com/littlepage/p/11617820.html
- 【设计模式】—— 解释器模式Interpret
- 【设计模式】—— 命令模式Commond
- 【设计模式】—— 职责链模式ChainOfResponsibility
- 【设计模式】—— 代理模式Proxy
- 【设计模式】—— 享元模式Flyweight
- 【设计模式】—— 外观模式Facade
- 【设计模式】—— 装饰模式Decorator
- 【设计模式】—— 组合模式Composite
- 【设计模式】—— 桥接模式Bridge
- 【插件开发】—— 1 Eclipse插件开发导盲
- 【插件开发】—— 4 SWT编程须知
- 【插件开发】—— 5 SWT控件以及布局使用
- 【插件开发】—— 6 SWT 复杂控件使用以及布局
- 【插件开发】—— 7 SWT布局详解,不能再详细了!
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Python部署rad+xray自动化
- 2.建立第一个django项目与配置
- Flutter基础widgets教程-Radio篇
- Django中的QuerySet
- Python—requests模块详解
- python爬虫伪装请求头---fake-useragent
- Flutter基础widgets教程-RaisedButton篇
- 记一次 excel vba 参考手册爬虫实战,不必要的一次爬虫。
- xray子域名扫描结果导出
- AWS的湖仓一体使用哪种数据湖格式进行衔接?
- python 行政区域地址标准化:业务经理填报的地址乱起八糟,高德接口有点厉害!
- python 行政区域地址标准化:业务经理填报的地址乱起八糟,高德接口有点厉害! -- 后续,使用分词思路完成解析
- pandas 一维台账数据与二维表格数据的转换
- Flutter基础widgets教程-Row篇
- padans 关于数据处理的杂谈 -- 时序数