Cod sursa(job #2736459)

Utilizator Ssebi1Dancau Sebastian Ssebi1 Data 3 aprilie 2021 14:54:28
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.07 kb
#include <bits/stdc++.h>
#include <list>
#include <fstream>

using namespace std;

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

void printList(list<int> g)
{
    list <int> :: iterator it;
    for(it = g.begin(); it != g.end(); ++it)
        cout << '\t' << *it;
    cout << '\n';
}

struct hashTable{
    list<int> l;
};

int main() {
    int buckets = 101111;
    hashTable hash[buckets];
    int n;
    f>>n;
    for(int i=0;i<n;i++)
    {
        int op,val;
        f>>op>>val;
        if(op == 1)
        {
            hash[val%buckets].l.push_back(val);
        }
        else if(op == 2)
        {
            hash[val%buckets].l.remove(val);
        }
        else if(op == 3)
        {
            int ok=0;
            list <int> :: iterator it;
            for(it = hash[val%buckets].l.begin(); it != hash[val%buckets].l.end(); ++it)
                if(*it == val)
                {
                    g<<1<<'\n';
                    ok = 1;
                    break;
                }
            if(ok==0)
                g<<0<<'\n';
        }
    }
    return 0;
}