Cod sursa(job #1047649)

Utilizator BuseSorinFMI Buse Sorin-Marian BuseSorin Data 4 decembrie 2013 19:41:55
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.87 kb
#include<iostream>
#include<fstream>
#include<vector>


using namespace std;


#define mod 666013

vector<int> V[mod];

int find(int x){
	int index = x%mod;
	for (int i = 0; i < V[index].size();i++){
		if (V[index][i] == x){
			return 1;
		}
	}
	return 0;
}

void insert(int x){
	int index = x%mod;
	if (find(x) == 0){
		V[index].push_back(x);
	}
}

void sterge(int x){
	int index = x%mod;
	for (int i = 0; i < V[index].size(); i++){
		if (V[index][i] == x){
			V[index][i] = V[index].back();
			V[index].pop_back();
			break;
		}
	}
}




int main(){
	fstream f("hashuri.in");
	ofstream o("hashuri.out");
	
	int n = 0; f >> n;
	int op = 0, x = 0;
	for (int i = 0; i < n; i++){
		f >> op >> x;
		if (op == 1){
			insert(x);
		}
		if (op == 2){
			sterge(x);
		}
		if (op == 3){
			o << find(x) << "\n";
		}
		
	}
	return 0;
}