Cod sursa(job #1054794)

Utilizator alexandrabadutBadut Alexandra alexandrabadut Data 14 decembrie 2013 10:18:40
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.08 kb
#include<fstream>
#include<vector>
#define HASH 576123
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

vector<int>L[HASH];
vector<int>::iterator it;

int T, x, y, i, op, exista;

int main(){

    fin>>T;
    for(;T;T--){
        fin>>op>>x;
        y=x%HASH;
        if(op==1){
            exista=0;
            for(it=L[y].begin();it!=L[y].end();it++){
                if(*it==x){
                    exista=1;
                }
            }
            if(!exista){
                L[y].push_back(x);
            }
        }
        if(op==2){
            for(it=L[y].begin();it!=L[y].end();it++){
                if (*it == x) {
                    L[y].erase(it);
                    break;
                }
            }
        }
        if(op==3){
            exista=0;
            for(it=L[y].begin();it!=L[y].end();it++){
                if(*it==x){
                    exista=1;
                    break;
                }
            }
            fout<<exista<<"\n";
        }
    }
    return 0;
}