1095 decoding PAT admission card (25 points)

Keywords: C C++ STL map printf

PAT admission number consists of 4 parts:

The first is the level, that is, T stands for the top level; A stands for class A; B stands for class B;
The 2nd to 4th digits are the examination room number, ranging from 101 to 999;
The 5th ~ 10th place is the examination date, with the format of year, month and day, accounting for 2 places in sequence;
The last 11 ~ 13 digits are the candidate number, ranging from 000 to 999.
A series of examinees' admission numbers and their scores are given. Please output various statistical information as required.

Input format:
Input first gives two positive integers N (≤ 10) in one line
4
)And M (≤ 100), respectively the number of candidates and the number of statistical requirements.

Next N lines, each line gives an examinee's admission number and its score (an integer in the interval [0100]) separated by spaces.

After the candidate information, M lines are given, and each line gives a statistical requirement. The format is: type instruction, where

Type 1 means that the scores of candidates at a specified level are required to be output in non ascending order of scores, and the corresponding instructions give letters representing the specified level;
Type 2 indicates that it is required to output the statistics of the number and total score of candidates in a specified examination room, and the corresponding instruction will give the number of the specified examination room;
Type 3 indicates that it is required to output the number of candidates on a specified date in the examination room, and the corresponding instruction gives the specified date in the same format as the date on the admission ticket.
Output format:
For each statistical requirement, first output Case #: requirement in one line, where # is the number of the requirement, starting from 1; The requirement is to copy the requirement given by the input. Then output the corresponding statistical results:

For the instruction of type 1, the output format is the same as the input examinee information format, that is, the admission ticket number and score. For candidates with parallel scores, output them incrementally according to the dictionary order of their admission number (the title shall ensure that there is no duplicate admission number);
Instructions of type 2 are output in the format of total number of people;
For the instruction of type 3, the output is in non increasing order, in the format of examination room number and total number of people. If the number of people is in parallel, it will be output in ascending order of examination room number.
If the query result is empty, NA is output.

Input example:

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

Output example:

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<bits/stdc++.h>
using namespace std;
struct student{
    string num;
    int score;
};

struct other{
    int num;
    string c;
};


struct man{
    string num;
    int score;
};


bool cmp(struct student s1,struct student s2){
    if(s1.score == s2.score) return s1.num < s2.num;
    return s1.score > s2.score;
}


int main(){
    int N,M;
    cin>>N>>M;
    struct student stu[N];
    struct other oth[M];
    for(int i=0;i<N;i++) cin>>stu[i].num>>stu[i].score;
    for(int i=0;i<M;i++) cin>>oth[i].num>>oth[i].c;


    for(int i=0;i<M;i++){
        vector<struct student> v;
        cout<<"Case "<<i+1<<": "<<oth[i].num<<" "<<oth[i].c<<endl;
        if(oth[i].num == 1){

            for(int j=0;j<N;j++){
                string temp = stu[j].num;
                if(temp.substr(0,1) == oth[i].c){
                    v.push_back(stu[j]);
                }
            }
            if(v.size() == 0){
                printf("NA\n");
                continue;
            }
                sort(v.begin(),v.end(),cmp);

                for(int i=0;i<v.size();i++){
                    printf("%s %d\n",v[i].num.c_str(),v[i].score);
                }

        }else if(oth[i].num == 2){
            int score = 0;
            for(int k=0;k<N;k++){
                string temp = stu[k].num;
                if(temp.substr(1,3) == oth[i].c){
                    v.push_back(stu[k]);
                    score += stu[k].score;
                }

            }
            if(v.size() == 0){
                printf("NA\n");
                continue;
            }
            printf("%d %d\n",v.size(),score);
        }else if(oth[i].num == 3){
                unordered_map<string,int> Map;
                for(int j=0;j<N;j++){
                string temp = stu[j].num;
                if(temp.substr(4,6) == oth[i].c){
                    Map[temp.substr(1,3)]++;
                }

            }

            for(auto x : Map){
                v.push_back({x.first,x.second});
            }

            if(v.size() == 0){
                printf("NA\n");
                continue;
            }

            sort(v.begin(),v.end(),cmp);

            for(int i=0;i<v.size();i++){
                printf("%s %d\n",v[i].num.c_str(),v[i].score);
            }



        }


    }
    return 0;
}

Posted by mdomel on Mon, 04 Oct 2021 13:53:38 -0700