Pagini recente » Cod sursa (job #2921631) | Cod sursa (job #832727) | Cod sursa (job #804404) | Cod sursa (job #921525) | Cod sursa (job #716465)
Cod sursa(job #716465)
#include<cstdio>
#include<fstream>
using namespace std;
int key;
char word[25],*p;
struct trie
{
int ok, nr;
trie *next[26];
trie()
{
for(int i=0;i<26;i++)
next[i]=0;
ok=0;
nr=0;
}
}*first, *aux;
int main()
{
int lit,NR;
freopen("trie.in","r",stdin);
freopen("trie.out","w",stdout);
first=new trie;
for(;scanf("%d%s", &key, word)+1;)
{
if(key==0)
{
for(aux=first,p=word;*p;p++)
{
lit=*p-'a';
if(!aux->next[lit])
aux->next[lit]=new trie;
aux=aux->next[lit];
aux->nr++;
}
aux->ok++;
continue;
}
if(key==1)
{
for(aux=first,p=word;*p;p++)
{
lit=*p-'a';
aux=aux->next[lit];
aux->nr--;
}
aux->ok--;
continue;
}
if(key==2)
{
for(aux=first, p=word;*p;p++)
{
lit=*p-'a';
aux=aux->next[lit];
if(!aux)
break;
}
if(aux!=0)
printf("%d\n", aux->ok);
else
printf("0\n");
continue;
}
if(key==3)
{
NR=0;
for(aux=first,p=word;*p;p++)
{
lit=*p-'a';
aux=aux->next[lit];
if(!aux||!aux->nr)
break;
NR++;
}
printf("%d\n",NR);
}
}
return 0;
}