Cod sursa(job #1036570)

Utilizator deividFlorentin Dumitru deivid Data 19 noiembrie 2013 14:39:11
Problema Dtcsu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
#include<stdio.h>
#include<algorithm>
#include<cassert>

#define mod 100007

using namespace std;

FILE*f=fopen("dtcsu.in","r");
FILE*g=fopen("dtcsu.out","w");

int ch,sol;
const int n = 276997;
char buff[25];
long long H[mod+5];

int main () {
	
	long long x = 0; int in = 0;
	for ( int i = 1 ; i <= n ; ++i ){
		
		fgets(buff,23,f);
		
		x = 0;
		ch = 0;
		while ( buff[ch] >= '0' && buff[ch] <= '9' ){
			x = x*10 + buff[ch]-'0';
			++ch;
		}
		
		if ( x % 11 == 0 )	continue ;
		H[ x % mod ] = x;
	}
	
	int q = 0;
	fgets(buff,23,f); ch = 0;
	while ( buff[ch] >= '0' && buff[ch] <= '9' ){
		q = q*10 + buff[ch]-'0';
		++ch;
	}
	
	for ( int i = 1 ; i <= q ; ++i ){
		fgets(buff,23,f);
		
		long long x = 0;
		ch = 0;
		while ( buff[ch] >= '0' && buff[ch] <= '9' ){
			x = x*10 + buff[ch]-'0';
			++ch;
		}
		
		if ( x == 0 )	continue ;
		while ( x % 11 == 0 )	x /= 11;
		
		if ( x == H[x % mod] )	++sol;
	}
	
	fprintf(g,"%d\n",sol);
	
	fclose(f);
	fclose(g);
	
	return 0;
}