Cod sursa(job #1157279)

Utilizator sorynsooSorin Soo sorynsoo Data 28 martie 2014 13:14:06
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.84 kb
#include <fstream>
#include <vector>
using namespace std;
#define mod 674987
ifstream cin("hashuri.in");
ofstream cout("hashuri.out");
vector<int> vt[mod+1];
int n,i,tip,x;
int check(int x)
{
    int poz=x % mod;
    for(int i=0; i<vt[poz].size(); i++)
        if(vt[poz][i]==x)
            return i;
    return -1;
}
void add(int x)
{
    int poz= x % mod;
    if(check(x)==-1)
        vt[poz].push_back(x);
}
void sterge(int x)
{
    int poz= x % mod, i;
    i=check(x);
    if(i!=-1)
        vt[poz].erase(vt[poz].begin()+i);
}
int main()
{
    cin>>n;
    for(i=1; i<=n; i++)
    {
        cin>>tip>>x;
        if(tip==1)
            add(x);
        if(tip==2)
            sterge(x);
        if(tip==3)
            if(check(x)!=-1)
                cout<<"1\n";
            else
                cout<<"0\n";
    }
}