Cod sursa(job #1852773)

Utilizator tanyafTanya Foransbergher tanyaf Data 21 ianuarie 2017 10:28:19
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.8 kb
#include <fstream>
#include <vector>
#define mod 666013
using namespace std;
ifstream f ("hashuri.in");
ofstream g ("hashuri.out");
vector <int> h[mod];
vector <int> :: iterator it;
int i, n, op, x, ind;
vector <int> :: iterator cauta(int x)
{
    for(it= h[ind].begin(); it!=h[ind].end(); it++)
        if (*it==x) return it;
    return it;
}
void add (int x)
{
    if(it==h[ind].begin()) h[ind].push_back(x);
}
void sterge (int x)
{
    if(it!=h[ind].end()) h[ind].erase(it);
}
void scrie (int x)
{
    if(it==h[ind].end()) g<<0<<'\n';
    else g<<1<<'\n';
}
int main()
{
    f>>n;
    for(i=1; i<=n; i++)
    {
        f>>op>>x;
        ind =x%mod;
        it=cauta(x);
        if(op==1) add(x);
        if(op==2) sterge(x);
        if(op==3) scrie(x);

    }
    return 0;
}