Cod sursa(job #2720927)

Utilizator LawrentiuTirisi Claudiu Lawrentiu Data 11 martie 2021 13:39:13
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.43 kb
#include <iostream>
#include <fstream>
#include <vector>
#define maxL 2000000000
#define prime 11273
using namespace std;
ifstream f("hashuri.in");
ofstream o("hashuri.out");

int main()
{

    vector<int> hash[prime];
    int n, op, num, rez;
    f >> n;

    for (int i = 0; i < n; i++)
    {
        f >> op >> num;
        rez = num % prime;

        switch (op)
        {
        case 1:
        {
            bool exists = 0;
            for (vector<int>::iterator i = hash[rez].begin(); i != hash[rez].end(); ++i)
                if (*i == num)
                    exists = 1;
            if (!exists)
                hash[rez].push_back(num);
            break;
        }
        case 2:
        {
            for (vector<int>::iterator i = hash[rez].begin(); i != hash[rez].end(); ++i)
            {
                if (*i == num)
                {
                    hash[rez].erase(i);
                    break;
                }
            }
            break;
        }
        case 3:
        {
            vector<int>::iterator i;
            for (i = hash[rez].begin(); i != hash[rez].end(); ++i)
            {
                if (*i == num)
                {
                    o << 1;
                    break;
                }
            }

            if (i == hash[rez].end())
                o << 0;
            o << "\n";
            break;
        }
        }
    }
}