Cod sursa(job #2630762)
Utilizator | Stanculescu Gabriel doyouhavethetime | Data | 27 iunie 2020 01:36:27 |
---|---|---|---|
Problema | Trie | Scor | 5 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.8 kb |
#include <bits/stdc++.h>
using namespace std;
map <string, int> M;
int query (string s) {
auto it=M.lower_bound(s);
advance(it, -1);
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 and cout << s << endl)
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] << endl;
else
fout << query(s) << endl;
return 0;
}