Cod sursa(job #2744675)

Utilizator MihaelaDanilaDanila Mihaela MihaelaDanila Data 24 aprilie 2021 22:38:37
Problema Hashuri Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.94 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

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

int n,operatie;
long x;

vector<long> h[10000];
/*
int hash_func(int x){
    return x%97;
}
*/

int index(long x){
    int poz = x%997;
    for(int i=0;i<h[poz].size();i++){
        if(h[poz][i] == x){
            h[poz][i] = 0;
            return 1;
        }
    }
    return 0;
}

void push(long x){
    //int poz = hash_func(x);
    if(!index(x)){
        h[x%997].push_back(x);
    }
}
void pop(long x){
    int poz = x%997;
    for(int i=0;i<h[poz].size();i++){
        if(h[poz][i] == x){
            h[poz].erase(h[poz].begin() + i);
        }
    }
}

int main(){
    f>>n;

    for(int i=0;i<n;i++){
        f>>operatie>>x;
        if(operatie == 1) push(x);
        if(operatie == 2) pop(x);
        if(operatie == 3) g<<index(x)<<'\n';
    }
    return 0;
}