Cod sursa(job #1032385)

Utilizator andreivFMI - vacaroiu andrei andreiv Data 15 noiembrie 2013 19:22:20
Problema Dtcsu Scor 0
Compilator cpp Status done
Runda FMI No Stress 4 Marime 1.16 kb
#include <cstdio>
#include <cstring>
 
#define CH (*s - '0')
 
using namespace std;
 
struct Trie {
    int cnt, nrfii;
    Trie *fiu[ 10];
 
    Trie() {
        cnt = nrfii = 0;
        memset( fiu, 0, sizeof( fiu ) );
    }
};
 
Trie *T = new Trie;
 
void ins( Trie *nod, char *s ) {
    if( *s == '\n' ) {
        nod->cnt ++; return;
    }
 
    if( nod->fiu[ CH ] == 0 ) {
        nod->fiu[ CH ] = new Trie;
        nod->nrfii ++;
    }
 
    ins( nod->fiu[ CH ], s+1 );
}
 
int que( Trie *nod, char *s ) {
    if( *s == '\n' )
        return nod->cnt;
 
    if( nod->fiu[ CH ] )
        return que( nod->fiu[ CH ], s+1 );
    return 0;
}
 
int main() {
    char line[20];
 
    freopen( "dtcsu.in", "r", stdin );
    freopen( "dtcsu.out", "w", stdout );
 
	
	for (int i = 276997 ; i; --i) //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	{
		fgets( line, 20, stdin );
		
		ins( T, line+2 ); 
/*		for (int j = 1; j <18; ++j)
			if (line[j] != '0')
				--line[j];	*/
    }
	int Q, rez =0;
	scanf("%d\n", &Q);
	Q = 0;
	while (Q--)
	{
		fgets( line, 20, stdin);
		rez += que( T, line+2);
	}
	printf("%d\n",rez);
    return 0;
}