Cod sursa(job #1034480)

Utilizator miu_mik93FMI - Paduraru Miruna miu_mik93 Data 17 noiembrie 2013 21:00:22
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.29 kb
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <assert.h>
#include <time.h>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <queue>
#include<cstdlib>
using namespace std;
	
#define MAXN 1000001

vector <int> a[MAXN];

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

void Add(int x)
{
	if ( !find(x) )
		a[x % MAXN].push_back(x);
}

void Delete(int x)
{
		for (vector<int>::iterator it = a[x % MAXN].begin(); it != a[x % MAXN].end(); it++)
			if ( *it == x )
			{
				a[x % MAXN].erase(it);
				break;
			}
}

int IsOrNot(int x)
{
	for (vector<int>::iterator it = a[x % MAXN].begin(); it != a[x % MAXN].end(); it++)
			if ( *it == x )
				return 1;
	return 0;
}

int main()
{
	FILE *f = fopen("hashuri.in", "r");
	FILE *g = fopen("hashuri.out", "w");
	int n;
	fscanf(f, "%d", &n);
	int x, nr;
	for (int i = 0; i < n; i++)
	{
		fscanf(f, "%d %d", &x, &nr);
		if (x == 1)
			Add(nr);
		else
			if (x == 2)
				Delete(nr);
			else
				if (x == 3)
					if( IsOrNot(nr) )
						fprintf(g, "1\n");
					else
						fprintf(g, "0\n");
	}
	fclose(f); fclose(g);
	return 0;
}