PAT 1039
输入
11 5
4 7
BOB5 DON2 FRA8 JAY9 KAT3 LOR6 ZOE1
1 4
ANN0 BOB5 JAY9 LOR6
2 7
ANN0 BOB5 FRA8 JAY9 JOE4 KAT3 LOR6
3 1
BOB5
5 9
AMY7 ANN0 BOB5 DON2 FRA8 JAY9 KAT3 LOR6 ZOE1
ZOE1 ANN0 BOB5 JOE4 JAY9 FRA8 DON2 AMY7 KAT3 LOR6 NON9
输出
ZOE1 2 4 5
ANN0 3 1 2 5
BOB5 5 1 2 3 4 5
JOE4 1 2
JAY9 4 1 2 4 5
FRA8 3 2 4 5
DON2 2 4 5
AMY7 1 5
KAT3 3 2 4 5
LOR6 4 1 2 4 5
NON9 0
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
using namespace std;
int change(char c[])
{
int res=0;
for(int i=0;i<3;i++)
{
res=res*26 + c[i]-'A';
}
res=res*10+c[3]-'0';
return res;
}
const int maxn=26*26*26*10+1;
set<int> a[maxn];
int main()
{
int n,k;
int id,num;
char name[5];
scanf("%d%d",&n,&k);
for(int i=0;i<k;i++)
{
scanf("%d%d",&id,&num);
for(int i=0;i<num;i++)
{
scanf("%s",name);
int temp=change(name);
a[temp].insert(id);
}
}
for(int i=0;i<n;i++)
{
scanf("%s",name);
int temp=change(name);
printf("%s %d",name,a[temp].size());
for( auto x:a[temp] )
{
printf(" %d",x);
}
printf("\n");
}
return 0;
}