原题解链接:https://ac.nowcoder.com/discuss/150007
暴力
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=2e5+10;
int n,m;
char s[310][2][3010];
int comfort(char *sr,char*s1)
{
int f=s1[0]=='-';
if(f)s1++;
for(int i=0;sr[i];i++)
{
int j;
for(j=0;s1[j];j++)
if(s1[j]==sr[i+j]||s1[j]=='*') continue;
else break;
if(!s1[j]) return f^1;
}
return f^0;
}
int main()
{
#ifdef shuaishuai
freopen("in.txt","r",stdin);
#endif // shuaishuai
scanf("%d%d\n",&n,&m);
for(int i=0;i<n;i++)
{
gets(s[i][0]);
gets(s[i][1]);
}
while(m--)
{
static char str[110];
gets(str);
int len=strlen(str);
str[len+1]=0;
unordered_set<int>r;
for(int i=0;i<n;i++)r.insert(i);
for(int i=0;str[i];)
{
int j=i;
while(str[j]&&str[j]!=' ')j++;
int idx=str[i+2]=='t';
while(str[i]!=':')i++;i++;
str[j]=0;
// puts(str+i);
for(unordered_set<int>::iterator k=r.begin();k!=r.end();)
{
int res=comfort(s[*k][idx],str+i);
if(res) {
k++;
continue;
}
else r.erase(k++);
}
i=j+1;
}
if(r.empty())puts("Not Found");
else {
// cout<<r.size()<<endl;
int cnt=0;
for(int i=0;i<n;i++)
{
if(r.count(i)) {
cnt++;
printf("%s%c",s[i][0]," \n"[cnt==r.size()]);
}
}
}
}
return 0;
}