分解PAT字符串进行不同部分统计
使用cin,cout,string超时
1. 原文
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 (≤104) and M (≤100), the numbers of cards and the queries, respectively.
Then N lines follow, each gives a card number and the owner’s score (integer in [0,100]), 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:
1 | 8 4 |
Sample Output:
1 | Case 1: 1 A |
2. 解析
14位字符串分别提取不同部分进行统计
- ABT级别 level
- 考场 site
- 年份 year
📝记录输入值 stu[i] –> node(char id[15],int grade) 数组
根据查询提取不同id部分
level: id[0]==level[0]
分数从大到小排,相同时按字母排 – sort
对应site的数量++,分数+=grade 存入map中
需要提交5-10位的year,2-4位的site –>map.vector
3. AC代码
1 |
|
使用cin,cout,string 出现超时
使用char[] 数据的提取转为int存储
1 | int a=0; |
Gitalking ...