zoukankan      html  css  js  c++  java
  • 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 and B 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 corresponding Term 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 corresponding Term 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 corresponding Term 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 where Nt is the total number of testees and Ns is their total score;
    • for a type 3 query, output in the format Site Nt where Site is the site number and Nt is the total number of testees at Site. The output must be in non-increasing order of Nt's, or in increasing order of site numbers if there is a tie of Nt.

    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

    解码PAT准考证,我们已知PAT准考证,第一位是TAB(代表基本),二到四是代表考场,五到十位代表日期,最后三位代表考场人数。

    我们要进行查询,如果输入1,则查询输入考试级别的分数降序,名字升序排序。如果输入2,则查询该考场人数和总分,输入3,则查询该日期的考场和考场中的人数。

    #include <iostream>
    #include <vector>
    #include <unordered_map>
    #include <algorithm>
    using namespace std;
    int N, M, choose;
    string tmp;
    pair<string, int> cards[11000];
    bool cmp(pair<string, int> p1, pair<string, int> p2) {
        return p1.second != p2.second ? p1.second > p2.second : p1.first < p2.first;
    }
    int main() {
        cin >> N >> M;
        for(int i = 0; i < N; i++)  
            cin >> cards[i].first >> cards[i].second;
        for(int c = 1; c <= M; c++) {
            cin >> choose >> tmp;
            printf("Case %d: %d %s
    ", c, choose, tmp.c_str());
            if(choose == 1) {
                vector<pair<string, int>> v;
                for(int i = 0; i < N; i++) 
                    if(cards[i].first[0] == tmp[0]) v.push_back(cards[i]);
                if(v.size() != 0) {
                    sort(v.begin(), v.end(), cmp);
                    for(auto x : v) printf("%s %d
    ", x.first.c_str(), x.second);
                } else printf("NA
    ");
            } else if(choose == 2) {
                int cnt = 0, all_score = 0;
                for(int i = 0; i < N; i++) {
                    if(cards[i].first.substr(1, 3) == tmp) {
                        cnt++; 
                        all_score += cards[i].second;
                    }
                }
                if(cnt != 0) printf("%d %d
    ", cnt, all_score);
                else printf("NA
    ");
            }else {
                unordered_map<string, int> m;
                for(int i = 0; i < N; i++) 
                    if(cards[i].first.substr(4, 6) == tmp) 
                        m[cards[i].first.substr(1, 3)]++;
                if(m.size() != 0) {
                    vector<pair<string, int>> v(m.begin(), m.end());
                    sort(v.begin(), v.end(), cmp);
                    for(auto x: v) printf("%s %d
    ", x.first.c_str(), x.second);
                } else printf("NA
    ");
            }
        }
        return 0;
    }
    // B 123 180908 127
    // 1 decreasing
    // 2 Nt Ns
    // 3 Nnumber testee
  • 相关阅读:
    微服务通过feign.RequestInterceptor传递参数
    fastdfs的storage的IP地址映射docker宿主地址
    Sentinel对Feign的支持
    SpringBoot设置MultipartFile文件大小限制
    SpringBoot+JWT@注解实现token验证
    springBoot 使用 mybatis-plus 实现分页
    MyBatis-Plus 使用xml文件
    MAC inode提示:正在查询SSLVPN网关参数... 查询SSLVPN 网关参数失败,请检查网络配置或联系
    MacOS launchctl 启动进程控制
    可执行Jar格式-1
  • 原文地址:https://www.cnblogs.com/littlepage/p/12817925.html
Copyright © 2011-2022 走看看