Pagini recente » Cod sursa (job #1357916) | Cod sursa (job #1810151) | Cod sursa (job #2917071) | Cod sursa (job #1451141) | Cod sursa (job #2982268)
#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;
}