Pagini recente » Cod sursa (job #1790671) | Cod sursa (job #455413) | Cod sursa (job #358182) | Cod sursa (job #1327280) | Cod sursa (job #382998)
Cod sursa(job #382998)
#include <stdio.h>
#include <string>
#include <set>
using namespace std;
#define maxl 30
#define maxn 100010
#define mp make_pair
#define ff first
#define ss second
int N, n;
char cuv[maxl];
int nr[maxn];
set < pair <string, int> > S;
int cmp(string s1, string s2)
{
int i, l1, l2;
l1 = s1.size(), l2 = s2.size();
for (i=0; i<min(l1, l2) && s1[i]==s2[i]; i++);
return i;
}
int main()
{
freopen("trie.in", "r", stdin);
freopen("trie.out", "w", stdout);
int tip, v1, v2;
set < pair <string, int> > :: iterator I;
string w = "";
w += 'z' + 1;
S.insert( mp(w, 0) );
while (!feof(stdin))
{
scanf("%d %s ", &tip, cuv);
w = string(cuv);
/*
if (tip == 0)
{
I = S.lower_bound( mp(w, 0));
if (I -> ff == w) nr[I -> ss]++;
else {
S.insert( mp( w, ++N));
nr[N] = 1;
}
}
if (tip == 1)
{
// I = S.lower_bound( mp( w, 0));
// nr[I -> ss]--;
// if (nr[I -> ss] == 0) S.erase(I);
}
if (tip == 2)
{
I = S.lower_bound( mp( w, 0));
if (I -> ff == w) printf("%d\n", nr[I -> ss]);
else printf("0\n");
}
if (tip == 3)
{
v1 = v2 = 0;
I = S.lower_bound( mp( w, 0));
v1 = cmp(I->ff, w);
if (I != S.begin())
{
I--;
v2 = cmp(I->ff, w);
}
printf("%d\n", max(v1, v2));
}
*/
}
return 0;
}