Cod sursa(job #1026314)

Utilizator jul123Iulia Duta jul123 Data 11 noiembrie 2013 14:58:47
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.11 kb
#include<iostream>
#include<vector>
#include<fstream>
#define MOD 666031

using namespace std;

vector <int>h[666031];
ofstream g( "hashuri.out");

bool find(int x)
{
    int j = x % MOD;
    for( vector <int>::iterator it = h[j].begin(); it != h[j].end(); it++)
        if(*it == x)
            return true;
    return false;

}
void adaugare(int x)
{
    if( find( x) == false)
        h[x % MOD].push_back( x);
}
void stergere(int x)
{
    vector<int>::iterator it;
    int j = x % MOD, ok=0;
    for(it=h[j].begin(); it!=h[j].end() && ok == 0; it++ )
        if(*it == x)
            {
            h[j].erase(it);
            ok = 1;
            }

}
void gasire(int x)
{
  if( find( x) == true)
    g<<'1';
    else
    g<<'0';
    g<<"\n";
}
int main()
{
    long long n, i, x, y ;
    ifstream f( "hashuri.in");

    f >> n;
    for(i = 0; i < n; i ++)
        {
            f >> x >> y;
            if( x == 1)
                adaugare( y);
            if( x == 2)
                stergere( y);
            if( x == 3)
                gasire( y);
        }
}