- 第一次写
tire
,有一些小trick吧。。。感觉没有以前感觉的难了。
#include <cstdio>
#include <string>
#include<iostream>
#include<vector>
#include <stack>
#include <queue>
#include <map>
#include <cstdlib>
#include<string.h>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int, int>pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef vector<vector<ll> >vvi;
typedef vector<ll> vi;
struct node
{
int cnt;
node *next[26];
node()
{
cnt = 0;
for (int i = 0; i < 26; i++)next[i] = NULL;
}
};
const int MAXN = 200000 + 50;
node head;
void insert(char s[])
{
node *tmp = &head;
for (int i = 0; s[i]; i++)
{
if (tmp->next[s[i] - 'a'] == NULL)tmp->next[s[i] - 'a'] = new node;
tmp = tmp->next[s[i] - 'a'];
tmp->cnt++;
}
}
int query(char s[])
{
node *tmp = &head;
int res = 0;
for (int i = 0;s[i]; i++)
{
if (tmp->next[s[i] - 'a'] == NULL)
{
res = 0;
break;
}
else
{
tmp = tmp->next[s[i] - 'a'];
res = tmp->cnt;
}
}
return res;
}
void init()
{
head.cnt = 0;
for (int i = 0; i < 26; i++)
head.next[i] = NULL;
}
int main()
{
init();
int n, m;
scanf("%d", &n);
char s[12];
while (n--)
{
scanf("%s", s);
insert(s);
}
scanf("%d", &m);
while (m--)
{
scanf("%s", s);
printf("%d\n", query(s));
}
}