Cod sursa(job #1021363)

Utilizator RobertSSamoilescu Robert RobertS Data 3 noiembrie 2013 18:53:15
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;

#define PRIM 113

vector<int>h[PRIM];
int n;

void solve(){
    ifstream fin ("hashuri.in");
    ofstream fout ("hashuri.out");

    fin >> n;
    int cmd, x;
    for(int i=1; i<=n; i++){
        fin >> cmd >> x;

        if(cmd == 1){
            h[x%PRIM].push_back(x);
        }else if(cmd == 2){
            int pos = -1;
            for(size_t i=0; i<h[x%PRIM].size(); i++){
                if(h[x%PRIM][i] == x) {pos = i; break;}
            }
            if(pos != -1)
            h[x%PRIM].erase(h[x%PRIM].begin() + pos);
        }else {
            bool found = false;
            for(size_t i=0; i<h[x%PRIM].size(); i++){
                if(h[x%PRIM][i] == x){found = true; break;}
            }

            if(found){
                fout << 1 << '\n';
            }else fout << 0 << '\n';
        }
    }

}

int main(){
    solve();
return 0;
}