Pagini recente » Cod sursa (job #2515728) | Cod sursa (job #492245) | Cod sursa (job #2437609) | Cod sursa (job #3254475) | Cod sursa (job #2664910)
#include <bits/stdc++.h>
using namespace std;
ifstream f("trie.in");
ofstream g("trie.out");
map <string, int> v;
int x;
string s;
int main()
{
while(f >> x >> s)
{
if(x == 0)
{
v[s] += 1;
}
else
if(x == 1)
{
v[s] -= 1;
}
else
if(x == 2)
{
g << v[s] << '\n';
}
else
if(x == 3)
{
int maxi = 0;
map <string, int>::iterator it = v.begin();
while(it != v.end())
{
string q = it -> first;
// cout << q << '\n';
if(it->second != 0)
{
if(s[0] != q[0])
{
it++;
continue;
}
else
{
// cout << '\n';
// cout << q[0] << " " << s[0] <<'\n';
int loc = 1;
while(q[loc] == s[loc] && loc < min(q.size(), s.size()))
{
// cout << q[loc] << " " << s[loc] <<'\n';
loc++;
}
maxi = max(loc, maxi);
}
}
it++;
}
g << maxi << '\n';
}
}
return 0;
}