Cod sursa(job #1711387)

Utilizator stoianmihailStoian Mihail stoianmihail Data 31 mai 2016 09:09:29
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb
#include <stdio.h>
#include <set>

using std::set;

#define MOD 243239

int N, h;
set <int> hash[MOD];
set <int>::iterator it;

void insert(int x) {
  hash[x % MOD].insert(x);
}

void erase(int x) {
  h = x % MOD;
  it = hash[h].find(x);
  if (it != hash[h].end()) {
    hash[h].erase(it);
  }
}

int find(int x) {
  h = x % MOD;
  return hash[h].find(x) != hash[h].end();
}

int main(void) {
  int task, x;
  FILE *f = fopen("hashuri.in", "r");
  freopen("hashuri.out", "w", stdout);

  fscanf(f, "%d", &N);
  while (N) {
    fscanf(f, "%d %d", &task, &x);
    switch (task) {
      case 1:
        insert(x);
        break;
      case 2:
        erase(x);
        break;
      case 3:
        fprintf(stdout, "%d\n", find(x));
    }
    N--;
  }
  fclose(f);
  fclose(stdout);

  /// Multumim Doamne!
  puts("Doamne ajuta!");
  return 0;
}