Cod sursa(job #809028)

Utilizator chimistuFMI Stirb Andrei chimistu Data 7 noiembrie 2012 19:51:59
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.07 kb
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<algorithm>
#define prim 2565151
using namespace std;

vector <long>v[prim];
FILE*f;
FILE*g;

long caut(long x)
{
    long i,rest;rest=x%prim;
    for (i=0;i<v[rest].size();i++)
        if (x==v[rest][i])
           return i;
    return -1;
}
long adauga(long x)
{
     long rest;rest=x%prim;
    if (caut(x)==-1)
       v[rest].push_back(x);
    }
long sterge(long x)
{   
    long poz,gasit,rest;rest=x%prim;
    gasit=caut(x);
    if (gasit!=-1)
    {
       poz=v[rest].size();
       v[rest][gasit]=v[rest][poz];
       v[rest].pop_back();
       }
}

int main()
{
    int n,i;
    long x;
    short op;
    f=fopen("hashuri.in","r");
    g=fopen("hashuri.out","w");
    fscanf(f,"%d",&n);
    for (i=1;i<=n;i++)
    {
        fscanf(f,"%d%d",&op,&x);
        switch (op)
        {case 1:adauga(x);break;
        case 2:sterge(x);break;
        case 3:if (caut(x)==-1) fprintf(g,"%d \n",0);
                     else fprintf(g,"%d \n",1);}
    }
    return 0;
}