Cod sursa(job #1034043)

Utilizator deividFlorentin Dumitru deivid Data 17 noiembrie 2013 17:06:46
Problema Dtcsu Scor 0
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,in,sol;
const int n = 276997;
int A[(n>>1)+10];
char buff[25];

int main () {
	
	for ( int j = 1 ; j <= 2 ; ++j ){
	A[0] = 0;
	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;
		}
		
		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+in+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 < A[1] || x > A[in] )	continue ;
		
		left = 1,right = in;
		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;
}