Cod sursa(job #2730237)

Utilizator KPP17Popescu Paul KPP17 Data 25 martie 2021 23:13:48
Problema Trie Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.62 kb
#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';
    }
}