1153 Decode Registration Card of PAT (25分)

// 一遍过的,还是挺开心的,比较代码量挺大的,这个题不涉及到任何算法,锻炼你的理解能力和打码水平

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_map>
using namespace std;
const int N = 1e4 + 10;
int n,m;
typedef pair<string,int> PSI;
vector<pair<string,int>>va;
vector<pair<string,int>>vb;
vector<pair<string,int>>vc;
unordered_map<string,pair<int,int>>mp1;
unordered_map<string,unordered_map<string,int>>mp2;

void print(int i,char c,vector<PSI>v)
{
    cout << "Case " << i << ": " << 1 << " " << c << endl;
    if(v.size())
        for(auto &x : v)
            cout << x.first << ' ' << x.second << endl;
    else
        cout << "NA" << endl;
    
}

int main()
{
    ios::sync_with_stdio(false);
    cin >> n >> m;
    string str;
    int score;
    
    for(int i = 0;i < n;i ++)
    {
        cin >> str >> score;
        char c = str[0];
        string site;
        for(int i = 1;i < 4;i ++)
            site += str[i];
        string date;
        for(int i = 4;i < 10;i ++)
            date += str[i];
        string id;
        for(int i = 10;i < 13;i ++)
            id += str[i];
        
        if(c == 'A'){
            va.push_back({str,score});
        }
        else if(c == 'B'){
            vb.push_back({str,score});
        }
        else{
            vc.push_back({str,score});
        }
        int sums = mp1[site].second + 1;
        int sumf = mp1[site].first + score;
        mp1[site] = make_pair(sumf,sums);
        mp2[date][site] ++;
    }
    
    sort(va.begin(),va.end(),[](PSI p1,PSI p2){
        if(p1.second == p2.second){
            return p1.first < p2.first;
        }
        return p1.second > p2.second;
    });
    sort(vb.begin(),vb.end(),[](PSI p1,PSI p2){
                if(p1.second == p2.second){
            return p1.first < p2.first;
        }
        return p1.second > p2.second;
    });
    sort(vc.begin(),vc.end(),[](PSI p1,PSI p2){
                if(p1.second == p2.second){
            return p1.first < p2.first;
        }
        return p1.second > p2.second;
    });
    
    for(int i = 1;i <= m;i ++)
    {
        int op;
        cin >> op;
        string str;
        if(op == 1){
            char c;
            cin >> c;
            if(c == 'A'){
                print(i,c,va);
            }
            else if(c == 'B'){
                print(i,c,vb);
            }
            else{
                print(i,c,vc);
            }
        }
        else if(op == 2){
            cin >> str;
            cout << "Case " << i << ": 2 " << str << endl;
            if(mp1[str].second)
                cout << mp1[str].second << ' ' << mp1[str].first << endl;
            else
                cout << "NA" << endl;
        }
        else
        {
            cin >> str;
            cout << "Case " << i << ": 3 " << str << endl;
            vector<PSI>v;
            for(auto &x : mp2[str])
            {
                v.push_back({x.first,x.second});
            }
            
            sort(v.begin(),v.end(),[](PSI p1,PSI p2){
                if(p1.second == p2.second){
                    return p1.first < p2.first;
                }
                return p1.second > p2.second;
            });
            if(v.size()){
                for(auto &x : v){
                 cout << x.first << ' ' << x.second << endl;
                }
            }else{
                cout << "NA" << endl;
            }

            
        }
    }
    
    
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值