Code:
#include<bits/stdc++.h>
#define mod 10007
using namespace std;
vector<int> hashs[10007];
int n,m,pos;
int hash1(char chs[]){
int ans = 0;
for(int i = 0;i<strlen(chs);i++){
ans = (ans*26+chs[i]+ mod) % mod;
}
return ans;
}
bool check(int i,int pos){
vector<int>::iterator it;
it = find(hashs[pos].begin(),hashs[pos].end(),i);
if(it!=hashs[pos].end())
return false;
else
return true;
}
int main()
{
cin>>n;getchar();
for(int i = 1;i<=n;i++){
int count;
cin>>count;
for(int j = 0;j<count;j++){
char chs[25];
scanf("%s",chs);
pos = hash1(chs);
if(check(i,pos))
hashs[pos].push_back(i);
}
}
cin>>m;getchar();
for(int i = 1;i<=m;i++){
char item[25];
scanf("%s",item);
int poss = hash1(item);
if(!hashs[poss].empty()){
for(int j = 0;j<hashs[poss].size();j++){
cout<<hashs[poss][j];
if(j!=hashs[poss].size()-1)
cout<<" ";
}
cout<<endl;
}
else
cout<<endl;
}
return 0;
}