Pagini recente » Cod sursa (job #2514568) | Cod sursa (job #2229736) | Cod sursa (job #178510) | Cod sursa (job #1236838) | Cod sursa (job #2453646)
#include <fstream>
#include <iostream>
#define mod 666013
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
struct nod{
int val;
nod *next;
};
nod *lista[mod];
int n;
int hFunc(int x) {
return x%mod;
}
void add(int x) {
nod *p = new nod;
p->val = x;
p->next = lista[hFunc(x)];
lista[hFunc(x)] = p;
}
bool query(int x) {
for(nod *p = lista[hFunc(x)]; p; p = p->next)
if(p->val == x)
return true;
return false;
}
void del(int x) {
nod *p = lista[hFunc(x)];
if(!query(x))
return;
if(p->val == x) {
lista[hFunc(x)] = p->next;
delete p;
return;
}
while(p-> next->val != x)
p = p->next;
nod *q = p->next;
p->next = q->next;
delete q;
}
int main() {
f >> n;
for(int i = 1; i <= n; i++) {
int op, x;
f >> op >> x;
cout << op << '\n';
if(op == 1)
add(x);
else if (op == 2)
del(x);
else
g << query(x) << '\n';
}
}