Cod sursa(job #1573979)

Utilizator marinaflommarina florentina marinaflom Data 20 ianuarie 2016 01:56:42
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.06 kb
#include <iostream>
#include <vector>
#include <fstream>

using namespace std;

vector <int> H[100000];

void op1(int x)
{
    int rest=x%100000;
    for(int i=0; i<H[rest].size(); i++)
    {
        if(H[rest][i]==x)
            return;
    }
    H[rest].push_back(x);
}

void op2(int x)
{
    int rest=x%100000;
    for(int i=0; i<H[rest].size(); i++)
    {
        if(H[rest][i]==x)
        {
            H[rest][i]=H[rest][H[rest].size()-1];
            H[rest].pop_back();
            return ;
        }
    }
}

bool op3(int x)
{
    int rest=x%100000;
    for(int i=0; i<H[rest].size(); i++)
        if(H[rest][i]==x)
            return 1;
    return 0;
}

int main()
{
    ifstream f("hashuri.in");
    ofstream g("hashuri.out");
    int n,operatie,x;
    f>>n;
    for(int i=1;i<=n;i++)
    {
        f>>operatie>>x;
        if(operatie==1)
            op1(x);
        if(operatie==2)
            op2(x);
        if(operatie==3)
            g<<op3(x)<<"\n";
    }
    f.close();
    g.close();
    return 0;
}