Cod sursa(job #1036547)

Utilizator deividFlorentin Dumitru deivid Data 19 noiembrie 2013 14:31:54
Problema Dtcsu Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.14 kb
#include<stdio.h>
#include<algorithm>

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 A[100000];

int main () {
	
	long long x = 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 ;
		A[++A[0]] = x;
	}
	
	int q = 0;
	fgets(buff,23,f); ch = 0;
	while ( buff[ch] >= '0' && buff[ch] <= '9' ){
		q = q*10 + buff[ch]-'0';
		++ch;
	}
	
	sort(A+1,A+A[0]+1);
	
	int left,middle,right;
	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;
		
		left = 1,right = A[0];
		while ( left <= right ){
			middle = (left+right)>>1;
			
			if ( A[middle] == x ){
				++sol; break ;
			}
			if ( A[middle] < x ){
				left = middle+1;
			}
			else{
				right = middle-1;
			}
		}
	}
	
	fprintf(g,"%d\n",sol);
	
	fclose(f);
	fclose(g);
	
	return 0;
}