1039. Course List for Student (25)
#include <stdio.h>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;
class CA
{
public:
enum{name_len=5};
priority_queue<int,vector<int>,greater<int> > couse[26][26][26][10];
void run();
void pushname(char *name,int cid);
void printname(char *name);
};
void CA::pushname(char *name,int cid)
{
couse[name[0]-'A'][name[1]-'A'][name[2]-'A'][name[3]-'0'].push(cid);
}
void CA::printname(char *name)
{
int cid;
priority_queue<int,vector<int>,greater<int> > &pq=couse[name[0]-'A'][name[1]-'A'][name[2]-'A'][name[3]-'0'];
printf("%s %d",name,pq.size());
while(!pq.empty())
{
cid=pq.top();pq.pop();
printf(" %d",cid);
}
printf("\n");
}
void CA::run()
{
int n,k,cid,cnum;
scanf("%d%d",&n,&k);
char name[name_len];
while(k-->0)
{
scanf("%d%d",&cid,&cnum);
while(cnum-->0)
{
scanf("%s",name);
pushname(name,cid);
}
}
while(n-->0)
{
scanf("%s",name);
printname(name);
}
}
int main()
{
// freopen("test.in","r",stdin);
CA *a=new CA;
a->run();
return 0;
}