这一题关键是对姓名处理 将其进行整数值映射。就因为这个点没把握,导致最后一个case超时。然后重新写了程序才通过
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
using namespace std;
int sum=0;
vector<int> s[26*26*26*10+1];
int hashname(char *name)
{
return (name[0]-'A')*26*26*10
+(name[1]-'A')*26*10
+(name[2]-'A')*10
+name[3]-'0';
}
int main()
{
int n,k;
int c,ns;
int size;
int t;
vector<int> numname;
vector<string> sname;
char name[5];
scanf("%d%d",&n,&k);
for(int i=0;i<k;i++)
{ scanf("%d%d",&c,&ns);
for(int j=0;j<ns;j++)
{scanf("%s",name);
t=hashname(name);
s[t].push_back(c);
}
}
for(int i=0;i<n;i++)
{
scanf("%s",name);
t=hashname(name);
sname.push_back(string(name));
numname.push_back(t);
sort(s[t].begin(),s[t].end());
}
for(int i=0;i<n;i++)
{
size=s[numname[i]].size();
cout<<sname[i];
printf(" %d",size);
for(int j=0;j<size;j++)
printf(" %d",s[numname[i]][j]);
printf("\n");
}
return 0;
}