Pagini recente » Cod sursa (job #2735679) | Cod sursa (job #504593) | Cod sursa (job #2957541) | Cod sursa (job #396093) | Cod sursa (job #2901455)
#include <cstdio>
#include <list>
using namespace std;
const int mod = 666013;
list<int> v[mod];
list<int>::iterator my_find(int nr, int *poz) {
*poz = nr % mod;
for (auto it = v[*poz].begin(); it != v[*poz].end(); it++) {
if (*it == nr)
return it;
}
return v[*poz].end();
}
void adauga(int nr) {
int poz;
auto it = my_find(nr, &poz);
if (it == v[poz].end()) {
v[poz].push_back(nr);
}
}
void sterge(int nr) {
int poz;
auto it = my_find(nr, &poz);
if (it != v[poz].end()) {
v[poz].erase(it);
}
}
bool gasete(int nr) {
int poz;
auto it = my_find(nr, &poz);
return it != v[poz].end();
}
int main() {
FILE *fin, *fout;
fin = fopen("hashuri.in", "r");
fout = fopen("hashuri.out", "w");
int op, nr, n;
fscanf(fin, "%d", &n);
for (int i = 0; i < n; i++) {
fscanf(fin, "%d%d", &op, &nr);
switch (op) {
case 1:
adauga(nr);
break;
case 2:
sterge(nr);
break;
default:
fprintf(fout, "%d\n", gasete(nr));
break;
}
}
fclose(fin);
fclose(fout);
return 0;
}