Pagini recente » Cod sursa (job #116338) | Cod sursa (job #572782) | Cod sursa (job #1051316) | Monitorul de evaluare | Cod sursa (job #2311977)
#include <unordered_map>
#include <fstream>
#include <cstdlib>
using namespace std;
ifstream cin("trie.in");
ofstream cout("trie.out");
unordered_map <string, int> f;
unordered_map <string, int> way;
inline void add(string s, int x)
{
string b;
for (auto &ch : s)
{
b += ch;
way[b] += x;
}
f[b] += x;
}
int main()
{
f.rehash(rand() % rand());
way.rehash(rand() % rand());
int type;
string s;
while (cin >> type >> s)
{
if (type == 0)
{
add(s, 1);
}
if (type == 1)
{
add(s, -1);
}
if (type == 2)
{
cout << f[s] << "\n";
}
if (type == 3)
{
int res = 0;
string b;
for (auto &ch : s)
{
b += ch;
if (way[b])
{
res = (int) b.size();
}
}
cout << res << "\n";
}
}
}