1153 Decode Registration Card of PAT (25 point(s))

思路:

非主流思路,先设计好数据结构,让记录在录入的时候对号入座,最后查询的时候整理或者直接输出。

1153 Decode Registration Card of PAT (25 point(s))

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.

Example:

#include<iostream>
#include<vector>
#include<cstring>
#include<map>
#include<set>
using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    map<char, map<int, set<string>>> Type1;
    map<int, pair<int, int>> Type2;
    map<int, map<int, int>>  Type3;
    for(int i = 0; i < N; i++) {
        string id;
        int score;
        cin >> id >> score;
        Type1[id[0]][score].insert(id);
        int site = atoi(id.substr(1, 3).c_str());
        Type2[site].first++;
        Type2[site].second += score;
        int date = atoi(id.substr(4, 6).c_str());
        Type3[date][site]++;
    }
    for(int i = 1; i <= M; i++) {
        printf("Case %d: ", i);
        int type;
        cin >> type;
        if(type == 1) {
            char term;
            cin >> term;
            printf("%d %c\n", type, term);
            if(Type1.count(term) != 0) {
                for(auto x = Type1[term].rbegin(); x != Type1[term].rend(); x++) {
                    for(auto y : x->second) {
                        printf("%s %d\n", y.c_str(), x->first);
                    }
                }
                continue;
            }
        } else if(type == 2) {
            char temp[4];
            cin >> temp;
            printf("%d %s\n", type, temp);
            int term = atoi(temp);
            if(Type2.count(term) != 0) {
                printf("%d %d\n", Type2[term].first, Type2[term].second);
                continue;
            }
        } else if(type == 3) {
            char temp[8];
            cin >> temp;
            printf("%d %s\n", type, temp);
            int term = atoi(temp);
            if(Type3.count(term) != 0 && Type3[term].size() > 0) {
                map<int, set<int>> result;
                for(auto x: Type3[term]) {
                    result[x.second].insert(x.first);
                }
                for(auto x = result.rbegin(); x != result.rend(); x++) {
                    for(auto y : x->second) {
                        printf("%03d %d\n", y, x->first);
                    }
                }
                continue;
            }
        } else {
            char term[20];
            cin >> term;
            printf("%d %s\n", type, term);
        }
        cout << "NA\n";
    }
}

猜你喜欢

转载自blog.csdn.net/u012571715/article/details/114638382