Pagini recente » Cod sursa (job #1290958) | Cod sursa (job #414937) | Cod sursa (job #1623076) | Cod sursa (job #1333019) | Cod sursa (job #3212418)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define pb push_back
ifstream fin("trie.in");
ofstream fout("trie.out");
const int N = 2e4+3;
struct nod {
int cnt, cntf;
nod* f[26];
nod(){
cnt = cntf = 0;
for (int i = 0; i < 26; i++)
f[i] = NULL;
}
} *root;
int t;
char w[23];
int main()
{
root = new nod;
while (fin >> t >> w){
if (!t){
nod *aux = root;
char *p = w;
while (*p != '\0'){
int c = *p - 'a';
if (aux->f[c] == NULL)
aux->f[c] = new nod;
aux = aux->f[c];
aux->cnt++; p++;
}
aux->cntf++;
}
else if (t == 1){
nod *aux = root;
char *p = w;
while (*p != '\0'){
int c = *p - 'a';
aux = aux->f[c];
aux->cnt--; p++;
}
aux->cntf--;
}
else if (t == 2){
nod *aux = root;
char *p = w;
while (*p != '\0'){
int c = *p - 'a';
if (aux->f[c] == NULL){
fout << 0 << '\n';
break;
}
aux = aux->f[c]; p++;
}
if (*p == '\0') fout << aux->cntf << '\n';
}
else {
nod *aux = root;
char *p = w; int l = 0;
while (*p != '\0'){
int c = *p - 'a';
if (aux->f[c] == NULL || !aux->f[c]->cnt){
break;
}
aux = aux->f[c]; p++; l++;
}
fout << l << '\n';
}
}
return 0;
}