Cod sursa(job #1030976)

Utilizator mugurelionutMugurel-Ionut Andreica mugurelionut Data 15 noiembrie 2013 17:15:04
Problema Dtcsu Scor 0
Compilator cpp Status done
Runda FMI No Stress 4 Marime 1.53 kb
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <vector>

using namespace std;

#define LMAX 1000

char stmp[LMAX];
int nread, poz, L;

void ReadInt(int& x) {
	while (1) {
		while (poz < L && (stmp[poz] < '0' || stmp[poz] > '9'))
			poz++;
		if (poz < L)
			break;
		fgets(stmp, LMAX - 2, stdin);
		L = strlen(stmp);
		poz = 0;
	}

	x = nread = 0;
	while (poz < L && stmp[poz] >= '0' && stmp[poz] <= '9') {
		x = x * 10 + stmp[poz] - '0';
		poz++;
		nread++;
	}

	if (nread == 0)
		exit(1);
}

void ReadLongLong(long long& x) {
	while (1) {
		while (poz < L && (stmp[poz] < '0' || stmp[poz] > '9'))
			poz++;
		if (poz < L)
			break;
		fgets(stmp, LMAX - 2, stdin);
		L = strlen(stmp);
		poz = 0;
	}

	x = nread = 0;
	while (poz < L && stmp[poz] >= '0' && stmp[poz] <= '9') {
		x = x * 10 + stmp[poz] - '0';
		poz++;
		nread++;
	}

	if (nread == 0)
		exit(1);
}

#define NMAX 276997
vector<long long> v;
long long N;
int i, Q, ans;

int Find(long long N) {
	int li = 0, ls = NMAX - 1, mid;
	while (li <= ls) {
		mid = (li + ls) >> 1;
		if (v[mid] == N)
			return 1;
		if (v[mid] < N)
			li = mid + 1;
		else
			ls = mid - 1;
	}
	return 0;
}

int main() {
	freopen("dtcsu.in", "r", stdin);
	freopen("dtcsu.out", "w", stdout);

	poz = L = 0;
	
	v.resize(NMAX);
	for (i = 0; i < NMAX; i++)
		ReadLongLong(v[i]);

	ReadInt(Q);
	ans = 0;
	
	while (Q--) {
		ReadLongLong(N);
		ans += Find(N);
	}

	printf("%d\n", ans);
	return 0;
}