PAT Basic 1095 PAT decoding ticket (25 points)

PAT ticket number consists of four parts:

  • No. 1 is the level that  T represents the top; A on behalf of Class; B on behalf of B;
  • 2 to 4 are numbered the examination room, ranging from 101 to 999;
  • 5 to 10 are test date format for the year, month and day in sequence each accounted for two;
  • 11 to 13 is the last candidate number, ranging from 000 to 999.

Now given a series of candidates ticket number and their accomplishments, you output a variety of statistical information as required.

Input formats:

Firstly, an input in a row two positive integers  N ( ≤) and  M ( ≤), respectively, and the number of candidates is the number of statistical requirements.

Next  N rows, each row candidates given a ticket number and fractions thereof (in the interval  integer [in), separated by a space therebetween.

After the candidate information, and then gives the  M rows, each row gives a statistical requirements, the format is: 类型 指令wherein

  • 类型 1 represents an output required by the fraction of non-ascending a grade specified level candidates, corresponding  指令 letters representing the level specified is given;
  • 类型 2 showing the examination requires a designated number of candidates and outputs statistical score, corresponding to  指令 the specified examination number is given;
  • 类型 It is the number of candidates in claim 3 represents a designated statistical examination date divided output corresponding to  指令 the specified date is given, on the same date ticket format.

Output formats:

Statistical requirements of each first output line  Case #: 要求, which  # is the number of the request, from a start; 要求 i.e., replication requires the input given. Then output the appropriate statistical results:

  • 类型 Instruction 1 is the same as the format candidate information input and output format, i.e.  准考证号 成绩. For parallel score candidates, lexicographically output increment its ticket number (subject to ensure that no duplicate ticket number);
  • 类型 Instruction 2, according to  人数 总分 the format of the output;
  • 类型 3 instruction, the output of the non-ascending order according to the number format  考场编号 总人数. If the number of parallel press the examination room number is incremented output order.

If the query result is empty, the output  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
Author: Chen Yue
Unit: Zhejiang University
Time limit: 200 ms
Memory Limit: 64 MB

 



#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;
}

 

Class B my side appeared the same mistake, is this NA, each should be printed.

Timeout, use unordered_map, or if the time-out, then the cout into printf, or if the time-out, then replace the cin scanf

Guess you like

Origin www.cnblogs.com/littlepage/p/11617828.html