Pagini recente » Cod sursa (job #1175410) | Cod sursa (job #2171385) | Cod sursa (job #11809) | Cod sursa (job #1978232) | Cod sursa (job #348366)
Cod sursa(job #348366)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
#define PRIM 666203
vector<int > H[PRIM];
int check(int temp)
{
vector<int >::iterator it;
for (it=H[temp%PRIM].begin(); it<H[temp%PRIM].end(); it++)
if (*it == temp)
return 1;
return 0;
}
void del(int temp)
{
for (int i=0; i<=H[temp%PRIM].size()-1; ++i)
{
if (H[temp%PRIM][i]==temp)
{
swap(H[temp%PRIM][i], H[temp%PRIM][H[temp%PRIM].size()-1]);
H[temp%PRIM].pop_back();
break;
}
}
}
void solve()
{
fstream f("test.in", ios::in);
fstream g("test.out", ios::out);
int n;
int aux;
int temp;
f>>n;
for (int i=1; i<=n; ++i)
{
f>>aux;
if (aux == 1)
{
f>>temp;
if (check(temp) == 0)
H[temp%PRIM].push_back(temp);
}
if (aux == 2)
{
f>>temp;
if (check(temp))
del(temp);
}
if (aux == 3)
{
f>>temp;
g<<check(temp)<<"\n";
}
}
f.close();
g.close();
}
int main()
{
solve();
return 0;
}