Pagini recente » Cod sursa (job #984829) | Cod sursa (job #1635714) | Statistici Okros Alexandru (OkrosAlexandru) | Cod sursa (job #1951133) | Cod sursa (job #640748)
Cod sursa(job #640748)
#include <cstdio>
#include <cstring>
#include <vector>
#define MOD 666013
using namespace std;
vector<int> lista[MOD + 5];
typedef vector<int>::iterator it;
char c;
char s[100];
int n, poz, l;
void citeste( int &x, int &poz ){
x = 0;
while (s[poz] <'0' || s[poz] > '9')
++poz;
while (poz < l && s[poz] != ' '){
x *= 10;
x += s[poz] - '0';
++poz;
}
}
it afla_iterator(int x){
int h_x = x % MOD;
for(it i = lista[h_x].begin(); i != lista[h_x].end(); ++i){
if (*i == x)
return i;
}
return lista[h_x].end();
}
void adauga( int x ){
int h_x = x % MOD;
if (afla_iterator(x) == lista[h_x].end())
lista[h_x].push_back(x);
}
void sterge( int x ){
int h_x = x % MOD;
it i = afla_iterator(x);
if (i != lista[h_x].end())
lista[h_x].erase(i);
}
int main(){
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
//citeste( n );
scanf("%d\n", &n);
for(int i=1; i<=n; ++i){
int x=0, y=0;
//gets(s);
//l = strlen(s);
scanf("%c", &c);
l = 0;
poz = 0;
s[l] = c;
++l;
while (c != '\n'){
scanf("%c", &c);
s[l] = c;
++l;
}
--l;
//printf("%d\n", l);
citeste(x, poz);
citeste(y, poz);
if (x == 1){
adauga( y );
}else if (x == 2){
sterge( y );
}else if (x == 3){
int h_x = y % MOD;
if (afla_iterator(y) == lista[h_x].end()) printf("%d\n", 0);
else printf("%d\n", 1);
}
}
fclose(stdin);
fclose(stdout);
return 0;
}