Cod sursa(job #982569)

Utilizator smaraldaSmaranda Dinu smaralda Data 9 august 2013 14:37:36
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include<string.h>
#include<vector>
#include<stdio.h>
#define MOD 666013
using namespace std;
vector <int> hash[MOD];
vector <int>::iterator it;
int main () {
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    int op,rest,x,nop,flag;
    scanf("%d",&nop);
    while( nop ) {
        scanf("%d%d",&op,&x);
        rest=x%MOD;
        if(op==1)
            hash[rest].push_back(x);
        if(op==2) {
            for(it=hash[rest].begin(); it!=hash[rest].end(); it++)
                if(*it==x) {
                    hash[rest].erase(it);
                    break;
                    }
            }

        if(op==3) {
            flag=0;
            for(it=hash[rest].begin(); it!=hash[rest].end() && !flag; it++)
                if(*it==x)
                    flag=1;
            printf("%d\n",flag);
            }
        nop--;
        }
    return 0;
}