Pagini recente » Cod sursa (job #916868) | Cod sursa (job #900856) | Cod sursa (job #735732) | Comisia | Cod sursa (job #2153313)
#include <bits/stdc++.h>
#define MOD 213161
#define NIL -1
const char* code[2] = {"1", "0"};
struct nod {
int val;
nod *urm;
};
class list {
private:
nod* l;
/** Cauta valoarea "x" in lista. **/
int exist(int x) {
if (l == NULL) {
return NIL;
}
int pos = 0;
nod* walk = l;
while (walk != NULL && walk -> val != x) {
walk = walk -> urm;
pos++;
}
return walk == NULL ? NIL : pos;
}
public:
list() {
l = NULL;
}
/** Adauga valoarea "x" in lista. **/
void insert(int x) {
if (exist(x) != NIL) {
return;
}
nod* nou = new nod;
nou -> val = x;
nou -> urm = l;
l = nou;
}
void find(int x) {
nod* walk = l;
while (walk != NULL && walk -> val != x) {
walk = walk -> urm;
}
puts(code[walk == NULL]);
}
/** Sterge valoarea "x" din lista. **/
void erase(int x) {
int pos = exist(x);
if (pos == NIL) {
return;
}
if (l -> urm == NULL) {
l = NULL;
} else if (pos == 0) {
l = l -> urm;
} else {
nod* prev = l;
nod* curr = prev -> urm;
while (curr -> val != x) {
prev = curr;
curr = curr -> urm;
}
prev -> urm = curr -> urm;
}
}
};
int N;
list hash[MOD];
int main(void) {
int task, x;
FILE *f = fopen("hashuri.in", "r");
freopen("hashuri.out", "w", stdout);
fscanf(f, "%d", &N);
while (N) {
fscanf(f, "%d %d", &task, &x);
if (task == 1) {
hash[x % MOD].insert(x);
} else if (task == 2) {
hash[x % MOD].erase(x);
} else {
hash[x % MOD].find(x);
}
N--;
}
fclose(f);
fclose(stdout);
/// Multumim Doamne!
puts("Doamne ajuta!");
return 0;
}