Cod sursa(job #778924)

Utilizator oana_popfmi - pop oana oana_pop Data 16 august 2012 11:42:56
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.26 kb
#include <fstream>
#include <vector>
#include <stdlib.h>
using namespace std;
const int M = 666013;

vector<int> hash[M];
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

vector<int>::iterator cauta(int x)
{
      vector<int>::iterator it;
      int index=x%M;
      for(it=hash[index].begin();it!=hash[index].end();it++)
           if(*it==x) return it;
      return hash[index].end();
}

int main()
{
    int i,n,x,indx,op;
    fin>>n;
    for(i=0; i<n; i++) 
    {
             fin>>op>>x;
             vector<int>::iterator it;
             indx=x%M;
             if(op==1){
                       it=cauta(x);
                       if(it==hash[indx].end())
                            hash[indx].push_back(x);
                       }
             else if(op==2){
                       it=cauta(x);
                       if(it!=hash[indx].end())
                            hash[indx].erase(it);
                       }
             else if(op==3){
                       it=cauta(x);
                       if(it!=hash[indx].end())
                       fout<<"1\n";
                       else
                       fout<<"0\n";
                       }
     }
     fin.close();
     fout.close();
     return 0;
}