1 条题解

  • 0
    @ 2026-9-30 12:43:55

    C++ :

    
    #include <cstdio>
    #include <set>
    #include <string>
    using namespace std;
    /* 每个首字母一个 set<(得奖次数, 姓名)>;begin() 就是「次数最少、并列取字典序最小」。 */
    static set<pair<int, string> > g[26];
    static char buf[105];
    int main(){
        int K, N;
        if(scanf("%d %d", &K, &N) != 2) return 0;
        for(int i = 0; i < K; i++){
            scanf("%s", buf);
            string s(buf);
            g[s[0] - 'a'].insert(make_pair(0, s));
        }
        for(int i = 0; i < N; i++){
            scanf("%s", buf);
            int c = buf[0] - 'a';
            if(g[c].empty()){ printf("?\n"); continue; }
            set<pair<int, string> >::iterator it = g[c].begin();
            int cnt = it->first;
            string nm = it->second;
            g[c].erase(it);
            g[c].insert(make_pair(cnt + 1, nm));
            printf("%s\n", nm.c_str());
        }
        return 0;
    }
    
    
    • 1

    信息

    ID
    2682
    时间
    1000ms
    内存
    256MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者