Pagini recente » Cod sursa (job #356253) | Cod sursa (job #1909470) | Cod sursa (job #989035) | Cod sursa (job #1160727) | Cod sursa (job #2630761)
#include <bits/stdc++.h>
using namespace std;
map <string, int> M;
int query (string s) {
cout << "Caut " << s << " in:\n";
for (auto it: M)
cout << it.first << ' ';
cout << endl;
auto it=M.lower_bound(s);
advance(it, -1);
cout << "Am gasit " << it->first << endl;
int i=0;
while (s[i]==it->first[i])
++i;
return i;
}
int main () {
ifstream fin ("trie.in");
ofstream fout ("trie.out");
string s;
int n;
while (fin >> n >> s)
if (n==0)
++M[s];
else
if (n==1) {
auto it=M.find(s);
if (it->second=1)
M.erase(it);
else
it->second--;
}
else
if (n==2)
fout << M[s] << '\n';
else
fout << query(s) << '\n';
return 0;
}