Pagini recente » Cod sursa (job #1039783) | Cod sursa (job #2917283) | Cod sursa (job #3260453) | Cod sursa (job #2862435) | Cod sursa (job #2730237)
#include <fstream>
#define mF "trie"
std::ifstream in(mF ".in");
std::ofstream out(mF ".out");
#include <map>
struct X {int a, b; std::map<char, X> V;} V;
#include <string>
int main()
{
int t, l; std::string S; for (X* x; x = &V, l = -1, in >> t >> S;) switch (t)
{
case 0: for (char e: S) x->a++, x = &x->V[e]; x->a++, x->b++; break;
case 1: for (char e: S) x->a--, x = &x->V[e]; x->a--, x->b--; break;
case 2: for (char e: S) x = &x->V[e]; out << x->b << '\n'; break;
case 3: for (char e: S) if (x->a) x = &x->V[e], l++; else break; out << l + (bool)x->a << '\n';
}
}