1039 Course List for Student (25 分)

1039 Course List for Student (25 分)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=40010;
const int M=26*26*26*10+11;

vector<int>selectcource[M];

int getid(char name[])
{
    int id=0;
    for(int i=0; i<3; i++)
    {
        id=id*26+(name[i]-'A');
    }
    id=id*10+name[3]-'0';
    return id;
}

int main()
{
    char name[5];
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=0; i<k; i++)
    {
        int course,x;
        scanf("%d%d",&course,&x);
        for(int j=0; j<x; j++)
        {
            scanf("%s",name);
            int id=getid(name);
            selectcource[id].push_back(course);
        }
    }

    for(int i=0; i<n; i++)
    {
        scanf("%s",name);
        int id=getid(name);
        sort(selectcource[id].begin(),selectcource[id].end());
        printf("%s %d",name,selectcource[id].size());
        for(int j=0; j<selectcource[id].size(); j++)
        {
            printf(" %d",selectcource[id][j]);
        }
        printf("\n");
    }
}

上一篇:_10.11


下一篇:1039 Course List for Student (25 分)