Pagini recente » Cod sursa (job #3201414) | Monitorul de evaluare | Cod sursa (job #1154112) | Cod sursa (job #2102043) | Cod sursa (job #1513614)
#include <set>
#include <map>
#include <cstring>
#include <fstream>
//#include <iostream>
using namespace std;
set<string> my_set;
map<string,int> my_hash;
int get_pref(string s1,string s2)
{
int N=min(s1.length(),s2.length()),i;
for(i=0;i<N;++i)
if (s1[i]!=s2[i])
return i;
return i;
}
ifstream f("trie.in");
ofstream g("trie.out");
#define cout g
int main()
{
int type;
while (f>>type)
{
string str;
f>>str;
if (type==0){ my_set.insert(str); my_hash[str]++;}
if (type==1){ my_set.erase(my_set.find(str)); my_hash[str]--;}
/*
if (type==2)
{
if (my_hash.find(str)!=my_hash.end()) cout<<my_hash[str]<<'\n';
else cout<<0<<'\n';
}
/*if (type==3)
{
int result=0;
if (my_set.empty()==false)
{
set<string>::iterator it=my_set.upper_bound(str);
if (it!=my_set.end()) result=get_pref(*it,str);
if (it!=my_set.begin())
{
--it;
result=max(result,get_pref(*it,str));
}
}
cout<<result<<'\n';
}*/
}
return 0;
}