Pagini recente » Cod sursa (job #683618) | Cod sursa (job #1639782) | Cod sursa (job #1969911) | Cod sursa (job #949731) | Cod sursa (job #2795732)
#include <stdio.h>
#include <vector>
#define DTCSU 276997
#define HASH_SIZE 9973
using namespace std;
vector <long long> hashTable[HASH_SIZE];
static inline int computeHash( long long x ) {
if ( x < 0 )
return 0;
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 ) {
int hashCode, n, i;
hashCode = computeHash( x );
n = hashTable[hashCode].size();
i = 0;
while ( i < n && hashTable[hashCode][i] != x )
i++;
if ( i == n )
hashTable[hashCode].push_back( x );
}
int main() {
FILE *fin, *fout;
int n, a, i;
fin = fopen( "dtcsu.in", "r" );
for ( i = 0; i < DTCSU; i++ ) {
fscanf( fin, "%d", &a );
addHashTable( a );
}
fout = fopen( "dtcsu.out", "w" );
fscanf( fin, "%d", &n );
for ( i = 0; i < n; i++ ) {
fscanf( fin, "%d", &a );
fprintf( fout, "%d\n", searchHashTable( a ) );
}
fclose( fin );
fclose( fout );
return 0;
}