1039 Course List for Student (25 分)【难度: 一般 / 知识点: 模拟 哈希表】

在这里插入图片描述
https://pintia.cn/problem-sets/994805342720868352/problems/994805447855292416

#include<bits/stdc++.h>
using namespace std;
unordered_map<string,vector<int>>mp;
int main(void)
{
    
    
    int n,k; cin>>n>>k;
    for(int i=0;i<k;i++)
    {
    
    
        int id,m; cin>>id>>m;
        for(int j=0;j<m;j++)
        {
    
    
            string s; cin>>s;
            mp[s].push_back(id);
        }
    }
    for(int i=0;i<n;i++)
    {
    
    
        string name; cin>>name;
        cout<<name;
        cout<<" "<<mp[name].size();
        auto temp=mp[name];
        sort(temp.begin(),temp.end());
        for(int j=0;j<temp.size();j++) cout<<" "<<temp[j];
        cout<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_46527915/article/details/120455498
今日推荐