zoukankan      html  css  js  c++  java
  • 1153 Decode Registration Card of PAT (25 分)

    sb题,不想过多描述==。

    struct Node
    {
        string id;
        int score;
        bool operator<(const Node &W) const
        {
            if(score != W.score) return score > W.score;
            return id < W.id;
        }
    };
    unordered_map<char,vector<Node>> mp1;
    unordered_map<string,PII> mp2;
    unordered_map<string,vector<Node>> mp3;
    int n,m;
    
    int main()
    {
        cin>>n>>m;
    
        for(int i=0;i<n;i++)
        {
            string id;
            int score;
            cin>>id>>score;
            mp1[id[0]].pb({id,score});
            mp2[id.substr(1,3)].fi++,mp2[id.substr(1,3)].se+=score;
            mp3[id.substr(4,6)].pb({id,score});
        }
    
        int kase=1;
        while(m--)
        {
            int t;
            cin>>t;
            if(t == 1)
            {
                char c;
                cin>>c;
                printf("Case %d: %d %c
    ",kase++,t,c);
                vector<Node> res;
                for(int i=0;i<mp1[c].size();i++)
                {
                    Node j=mp1[c][i];
                    res.pb(j);
                }
    
                sort(res.begin(),res.end());
                if(res.size() == 0) puts("NA");
                else
                {
                    for(int i=0;i<res.size();i++)
                    {
                        Node j=res[i];
                        printf("%s %d
    ",j.id.c_str(),j.score);
                    }
                }
            }
            else if(t == 2)
            {
                string site;
                cin>>site;
                printf("Case %d: %d %s
    ",kase++,t,site.c_str());
                if(mp2[site].fi == 0) puts("NA");
                else
                    printf("%d %d",mp2[site].fi,mp2[site].se);
            }
            else
            {
                string date;
                cin>>date;
                printf("Case %d: %d %s
    ",kase++,t,date.c_str());
                unordered_map<string,int> res;
                for(int i=0;i<mp3[date].size();i++)
                {
                    Node j=mp3[date][i];
                    res[j.id.substr(1,3)]++;
                }
    
                vector<Node> ans;
                for(auto t:res)
                    ans.pb({t.fi,t.se});
    
                sort(ans.begin(),ans.end());
                if(ans.size() == 0) puts("NA");
                else
                {
                    for(int i=0;i<ans.size();i++)
                    {
                        Node j=ans[i];
                        printf("%s %d
    ",j.id.c_str(),j.score);
                    }
                }
    
            }
        }
        //system("pause");
        return 0;
    }
    
  • 相关阅读:
    遍历文件夹及子文件夹_函数
    wbadmin与vssadmin
    WSB备份到远程共享文件夹的限制
    Linux 性能工具集
    shell 与 空格
    Git 仓库结构 (二)***
    Linux下scp的用法***
    FINDSTR 命令使用详解
    Git 的origin和master分析 ***
    Git push *****
  • 原文地址:https://www.cnblogs.com/fxh0707/p/14485403.html
Copyright © 2011-2022 走看看