Pagini recente » Cod sursa (job #1465626) | Cod sursa (job #1877601) | Cod sursa (job #1748895) | Cod sursa (job #2540985) | Cod sursa (job #3354069)
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
struct Node;
const int MX = 1000001;
const int MOD = 999.983;
Node* hashmap[MX];
Node* srch{nullptr};
Node* aux{nullptr};
struct Node {
int val;
Node* next;
Node(int val, Node* next) {
this->val = val;
this->next = next;
}
};
void push(Node* &head, int val) {
head = new Node(val, head);
};
bool isval(Node* &head, int val) {
if (head == nullptr) {
return false;
} else {
if (head->val == val) {
return true;
}
}
srch = head;
while (srch->next != nullptr) {
if (srch->next->val == val) {
return true;
}
srch = srch->next;
}
return false;
}
void ersval(Node* &head, int val) {
if (head == nullptr) {
return;
} else {
if (head->val == val) {
aux = head;
head = head->next;
delete aux;
return;
}
}
srch = head;
while (srch->next != nullptr) {
if (srch->next->val == val) {
aux = srch->next;
srch->next = srch->next->next;
delete aux;
return;
}
srch = srch->next;
}
}
int main() {
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
for (int i = 0; i < MX; i++) {
hashmap[i] = nullptr;
}
int n;
cin >> n;
int op, v;
int hashed = -1;
for (int i = 0; i < n; i++) {
cin >> op >> v;
hashed = v % MOD;
if (op == 1) {
if (!isval(hashmap[hashed], v)) {
push(hashmap[hashed], v);
}
} else if (op == 2) {
ersval(hashmap[hashed], v);
} else if (op == 3) {
if (isval(hashmap[hashed], v)) {
cout << 1 << "\n";
} else {
cout << 0 << "\n";
}
}
}
return 0;
}