Cod sursa(job #2663522)

Utilizator cristiemanuelstroe cristian emanuel cristiemanuel Data 26 octombrie 2020 17:34:50
Problema Hashuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.72 kb
#include  <fstream>
#include  <iostream>
#include  <vector>

using namespace std;

ifstream in("hashuri.in");
ofstream out("hashuri.out");

const int mod = 177;
vector<int>H[mod];
vector<int>::iterator it;
int n;

int exista(int h, int x){
  for(it = H[h].begin(); it != H[h].end(); it++)
    if(*it == x)
      return *it;
  return 0;
}

int main(){
  in>>n;
  for(; n; n--){
    int x, c;
    in>>c>>x;
    int h = x%mod;
    int cond = exista(h, x);
    if(c == 1){
      if(!cond)
        H[h].push_back(x);
    }
    else if(c == 2){
      if(cond){
        H[h].erase(*it);
      }
    }
    else{
      if(cond)
        out<<1<<'\n';
      else
        out<<0<<'\n';
      }
  }
}