Pagini recente » Cod sursa (job #2814320) | Cod sursa (job #297087) | Cod sursa (job #102193) | Cod sursa (job #2520295) | Cod sursa (job #3143130)
#include <fstream>
using namespace std;
using pii = pair<int,int>;
ifstream cin("hashuri.in");
ofstream cout("hashuri.out");
int m , op , x;
struct trie{
int hm = 0;
trie *next[10];
void add(int x){
if(x==0) return;
if(next[x%10]==nullptr){
next[x%10] = new trie;
}
next[x%10]->hm++;
next[x%10]->add(x/10);
}
bool del(int x){
if(x==0) return 1;
if(next[x%10]==nullptr){
return 0;
}
bool val = next[x%10]->del(x/10);
if(val) next[x%10]->hm--;
if(!next[x%10]->hm) next[x%10] = nullptr;
return val;
}
bool chk(int x){
if(x==0) return 1;
if(next[x%10]==nullptr) return 0;
return next[x%10]->chk(x/10);
}
}t;
signed main(){
cin >> m;
for(int i = 1 ; i <= m ; i++){
cin >> op >> x;
if(op==1) t.add(x);
if(op==2) t.del(x);
if(op==3){
if(t.chk(x)) cout << 1 << '\n';
else cout << 0 << '\n';
}
}
return 0;
}