include [HTML_REMOVED]
using namespace std;
const int N = 100010;
int son[N][26],idx,cnt[N],i;
char str[N],op;
void insert(char str[])
{
int p = 0;
for(i = 0;str[i];i)
{
int u = str[i] - ‘a’;
if(!son[p][u])
{
son[p][u] = idx;
}
p = son[p][u];
}
cnt[p]++;
}
int query(char str[])
{
int p = 0;
for(i = 0;str[i];i++)
{
int u = str[i] - ‘a’;
if(!son[p][u])
{
return 0;
}
p = son[p][u];
}
return cnt[p];
}
int main()
{
int n;
scanf(“%d”,&n);
while(n –)
{
scanf(“%s%s”,&op,str);
if(op == ‘I’)
{
insert(str);
}
else
{
printf(“%d\n”,query(str));
}
}
return 0;
}
不会用代码框吗?丑的一p
向大佬学习,下次用。