Cod sursa(job #2580545)

Utilizator MihclerioVladimir Chim Mihclerio Data 13 martie 2020 18:54:38
Problema Trie Scor 65
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.83 kb
#include <bits/stdc++.h>

const int nmax=1e5+3;
const int inf=2e9+3;

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    freopen("trie.in","r",stdin);
    freopen("trie.out","w",stdout);

    int k;
    string s;
    map<string,int>h,pr;
    while(cin>>k>>s)
    {
      if(k==0)
      {
        h[s]++;
        while(s.size())
        {
          pr[s]++;
          s.pop_back();
        }
      } else
      if(k==1)
      {
        if(h[s])
        {
          h[s]--;
          while(s.size())
          {
            pr[s]--;
            s.pop_back();
          }
        }
      } else
      if(k==2)
      {
        cout<<h[s]<<"\n";
      } else
      {
        while(s.size() && !pr[s]) s.pop_back();
        cout<<s.size()<<"\n";
      }
    }

}