Pagini recente » Cod sursa (job #682992) | Cod sursa (job #3284837) | Cod sursa (job #2630846) | Cod sursa (job #1784140) | Cod sursa (job #226145)
Cod sursa(job #226145)
Utilizator |
Lucian Boca amadaeus |
Data |
1 decembrie 2008 03:24:04 |
Problema |
Trie |
Scor |
Ascuns |
Compilator |
cpp |
Status |
done |
Runda |
|
Marime |
1.09 kb |
#include <cstdio>
#include <string>
#include <list>
using namespace std;
#define TR(C,i) \
for( typeof(C.begin()) i = C.begin(); i != C.end(); i++ )
list< string > L;
void del( char *s ) {
string t( s );
TR( L, it )
if( *it == t ) {
L.erase( it );
break;
}
}
int que( char *s ) {
string t( s );
int cnt = 0;
TR( L, it )
if( *it == t )
cnt++;
return cnt;
}
int pre( char *s ) {
string t1( s ), t2;
int i, l1, l2, res = 0;
l1 = t1.length() - 1;
TR( L, it ) {
t2 = *it; l2 = t2.length() - 1;
for( i = 0; i < l1 && i < l2 && t1[i] == t2[i]; i++ );
res = res < i ? i : res;
}
return res;
}
int main() {
char line[ 32 ];
freopen( "trie.in", "r", stdin );
freopen( "trie.out", "w", stdout );
fgets( line, 32, stdin );
while( !feof( stdin ) ) {
switch( line[0] ) {
case '0': L.push_back( line+2 ); break;
case '1': del( line+2 ); break;
case '2': printf( "%d\n", que( line+2 ) ); break;
case '3': printf( "%d\n", pre( line+2 ) ); break;
}
fgets( line, 32, stdin );
}
return 0;
}