Cod sursa(job #2982268)

Utilizator superffffalexandru radu superffff Data 19 februarie 2023 19:53:19
Problema Trie Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.08 kb
#include <iostream>
#include <fstream>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cctype>
#include <unordered_map>
#include <cmath>
#include <bitset>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
ifstream in("trie.in");
ofstream out("trie.out");
int a,b,c,d,e,f,g,i,j,k,l,m,n,o,q,r,s,S,t,T,x,y,z,ok,nr,w,C,k1,k2,poz,pas,Max,mid,nways,MOD;
map <string,int>M;
string str,aux;
int main()
{
   while(in>>x>>str){
    if(x==0){
        M[str]++;
    }
    if(x==1){
        M[str]--;
   if(M[str]==0) {M.erase(M.find(str));}
    }
    if(x==2){
            if(M.find(str)==M.end()) {out<<0<<'\n';}
        else {out<<M[str]<<'\n';}
    }
    if(x==3){
         m=str.size();
         Max=0;
      for(auto w:M){
            n=w.first.size();
            i=0;
            j=0;
            k=0;
        while(i<n && j<n && w.first[i]==str[j]){
            k++;
            i++;
            j++;
        }
        if(k>Max) {Max=k;}
          }
          out<<Max<<'\n';
    }

   }
   return 0;
}