Pagini recente » Cod sursa (job #661220) | Cod sursa (job #2967422) | Cod sursa (job #2971935)
#include <bits/stdc++.h>
using namespace std;
#if 1
#define cin fin
#define cout fout
ifstream fin("trie.in");
ofstream fout("trie.out");
#endif // 1
int main()
{
string s;
int op;
map<string, int> m;
while (cin >> op >> s) {
if (op == 0) {
m[s]++;
}
else if (op == 1) {
int v = --m[s];
if (v == 0)
m.erase(s);
}
else if (op == 2) {
auto it = m.find(s);
if (it != m.end()) {
cout << it->second << "\n";
}
else cout << "0\n";
}
else if (op == 3) {
for (int i = s.size(); i > 0; i--) {
string w = s.substr(0, i);
auto it = m.lower_bound(w);
if (it == m.end())
continue;
if (it->first.size() < i)
continue;
if (w == it->first.substr(0, i)) {
cout << i << "\n";
goto nd;
}
}
cout << 0 << "\n";
nd: {}
}
}
}