Cod sursa(job #1747588)

Utilizator mihaiadelinamihai adelina mihaiadelina Data 25 august 2016 10:53:35
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.98 kb
#include <iostream>
#include <fstream>
#include <vector>
#define Max 1000000
using namespace std;
ifstream fin ("hashuri.in");
ofstream fout ("hashuri.out");
vector<int> rest[Max];
int main() {
	int n, i, j, v, operatie, valoare, poz;
	bool ok;
	fin >> n;
	for (i = 0; i < n; i++) {
		fin >> operatie >> valoare;
		v = valoare % Max;
		if (operatie == 1) {
			ok = false;
			for (j = 0; j < rest[v].size(); j++) {
				if (rest[v][j] == valoare) {
					ok = true;
				}
			}
			if (valoare) {
				rest[v].push_back(valoare);
			}
			continue;
		}
		if (operatie == 2) {
			poz = -1;
			for (j = 0; j < rest[v].size(); j++) {
				if (rest[v][j] == valoare) {
					poz = j;
				}
			}
			if (poz >= 0) {
				swap(rest[v][poz], rest[v][rest[v].size() - 1]);
				rest[v].pop_back();
			}
			continue;

		}
		poz = -1;
		for (j = 0; j < rest[v].size(); j++){
			if (rest[v][j] == valoare) {
				poz = j;
			}
		}
		if (poz >= 0) {
			fout << 1 << "\n";
		}
		else {
			fout << 0 << "\n";
		}
	}
	return 0;
}