Cod sursa(job #479564)

Utilizator andra23Laura Draghici andra23 Data 24 august 2010 14:49:13
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.91 kb
#include<iostream>
#include<fstream>
#include<vector>
#define r 699967

using namespace std;

ifstream f("hashuri.in");
ofstream g("hashuri.out");

vector<int> a[r+10];

int search(int x){
    int h = x%r;
    for (int i = 0; i < a[h].size(); i++)
        if (a[h][i] == x)
            return 1;
    return 0;    
}

void add(int x){
    if (search(x) == 1)
        return;
    int h = x%r;
    a[h].push_back(x);
}

void del(int x){
    int h = x%r;
    for (int i = 0; i < a[h].size(); i++)
        if (a[h][i] == x){
            a[h].erase(a[h].begin()+i); 
            break;
        }   
}

int main(){
    int n, t, x, i;
    f>>n;
    for (i = 1 ; i <= n; i++){
        f>>t>>x;
        if (t == 1)
            add(x);
        else    
            if (t == 2)
                del(x);
            else 
                g<<search(x)<<'\n';      
    }
    
    return 0;
}