Pagini recente » Cod sursa (job #376621) | Cod sursa (job #2935533) | Cod sursa (job #301830) | Cod sursa (job #928197) | Cod sursa (job #2795749)
#include <stdio.h>
#include <vector>
#include <ctype.h>
#define DTCSU 276997
#define HASH_SIZE 9973
using namespace std;
FILE *fin;
vector <long long> hashTable[HASH_SIZE];
static inline int computeHash( long long x ) {
return x % HASH_SIZE;
}
bool searchHashTable( long long x ) {
int hashCode, n, i;
hashCode = computeHash( x );
n = hashTable[hashCode].size();
i = 0;
while ( i < n && hashTable[hashCode][i] != x )
i++;
return i < n;
}
void addHashTable( long long x ) {
hashTable[computeHash( x )].push_back( x );
}
long long getNum() {
char ch;
long long n;
ch = getc( fin );
while ( isspace( ch ) && ch != EOF )
ch = getc( fin );
n = 0;
while ( isdigit( ch ) ) {
n = n * 10 + ch - '0';
ch = getc( fin );
}
return n;
}
int main() {
FILE *fout;
int n, dtcsu, i;
long long a;
fin = fopen( "dtcsu.in", "r" );
for ( i = 0; i < DTCSU; i++ ) {
a = getNum();
addHashTable( a );
}
dtcsu = 0;
n = getNum();
for ( i = 0; i < n; i++ ) {
a = getNum();
dtcsu += searchHashTable( a );
}
fclose( fin );
fout = fopen( "dtcsu.out", "w" );
fprintf( fout, "%d", dtcsu );
fclose( fout );
return 0;
}