1039 Course List for Student (25 分)

水题,用c++读入最后一个点会超时。

const int N=40010;
map<string,vector<int>> mp;
int n,m;

int main()
{
    cin>>n>>m;

    while(m--)
    {
        int course,k;
        scanf("%d%d",&course,&k);
        for(int j=0;j<k;j++)
        {
            string name;
            name.resize(4);
            scanf("%s",&name[0]);
            mp[name].pb(course);
        }
    }

    for(int i=0;i<n;i++)
    {
        string name;
        name.resize(4);
        scanf("%s",&name[0]);
        printf("%s %d",name.c_str(),mp[name].size());
        sort(mp[name].begin(),mp[name].end());
        for(int i=0;i<mp[name].size();i++)
            printf(" %d",mp[name][i]);
        puts("");
    }
    //system("pause");
    return 0;
}
原文地址:https://www.cnblogs.com/fxh0707/p/14408433.html