Cod sursa(job #2622439)

Utilizator grecuGrecu Cristian grecu Data 1 iunie 2020 12:27:04
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.94 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

//const int mod = 66666;
vector<int> hasht[66666];

void add(int x){
    hasht[x % 66666].push_back(x);
}

void deleteh(int x){
    int m = x % 66666;
    for (int i = 0; i < hasht[m].size(); i++)
        if(hasht[m][i] == x)
            hasht[m].erase(hasht[m].begin()+i);


}

int searchh(int x){
    int m = x % 66666;
    for (int i = 0; i < hasht[m].size(); i++){
        if(hasht[m][i] == x){
            return 1;
        }
    }
    return 0;
}


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

    int n, x, y;
    f>>n;
    for(int i = 0; i < n; i++){
        f >> x >> y;
        if(x == 1)
           add(y);
        else
            if(x == 2)
                deleteh(y);
            else
                g << searchh(y) << endl;

        }
    f.close();
    g.close();
    return 0;
}