Cod sursa(job #1047721)

Utilizator chimistuFMI Stirb Andrei chimistu Data 4 decembrie 2013 20:35:48
Problema Generare de permutari Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.06 kb
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<algorithm>
#define prim 666013
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;
}
void adauga(long x)
{
     long rest;rest=x%prim;
    if (caut(x)==-1)
       v[rest].push_back(x);
    }
void sterge(long long x)
{   
    long poz,gasit,rest;rest=x%prim;
    gasit=caut(x);
    if (gasit!=-1)
    {
       poz=v[rest].size()-1;
       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;
}