Cod sursa(job #2664910)
Utilizator | Data | 29 octombrie 2020 18:29:53 | |
---|---|---|---|
Problema | Trie | Scor | 40 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 1.41 kb |
#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;
}