Cod sursa(job #1085833)

Utilizator Mitsa3Neamt Mihai Mitsa3 Data 17 ianuarie 2014 14:24:03
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.94 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
#define MOD 666013
#define cheie x%MOD
vector < int > vec[MOD];
int caut(int x)
{
    for(int i = 0; i<vec[cheie].size(); i++)
        if(vec[cheie][i]==x)
            return i;
    return -1;
}
void op1(int x)
{
    if(caut(x) == -1)
        vec[cheie].push_back(x);
}
void op2(int x)
{
    int indice = caut(x);
    if(indice != -1) {
        swap(vec[cheie][indice],vec[cheie][vec[cheie].size()-1]);
        vec[cheie].pop_back();
    }
}
bool op3(int x)
{
    if(caut(x) != -1)
        return 1;
    return 0;

}
int main()
{
    int n, op, nr;
    fin >> n;
    for(int j = 1; j<=n; j++) {
        fin >> op >> nr;
        if(op==1)
            op1(nr);
        if(op==2)
            op2(nr);
        if(op==3)
            fout << op3(nr) << "\n";

    }
    return 0;
}