#include #include #include #include #include int arr[2323]; char ss[23]; char ttt[23]; struct Node{ Node *child[26]; int cnt; }; Node* root; Node* addN(){ Node* u = new Node; for(int i = 0; i < 26; i++){ u->child[i] = NULL; } return u; } void removeT(Node* u){ if(u == NULL) return ; for(int i = 0; i < 26; i++) removeT(u->child[i]); delete (u); u = NULL; return ; } void inSert(char *s){ Node* u = root; int len = strlen(s); for(int i = 0; i < len; i++){ int k = s[i]-'a'; if(u->child[k] == NULL){ Node* newnode = addN(); u->child[k] = newnode; u = newnode; u->cnt = 1; }else{ u = u->child[k]; u->cnt++; } } } int findS(char *s){ Node* u = root;int len = strlen(s); for(int i = 0; i child[k]!=NULL) u = u->child[k]; else return 0; } return u->cnt; } void deleteS(char *s){ int k = findS(s); if(!k) return ; int len = strlen(s); Node *u = root->child[s[0]-'a']; Node *pre = root; for(int i = 1; i < len; i++){ u->cnt -= k; if(u->cnt == 0){ pre->child[s[i-1]-'a'] = NULL; removeT(u); return ; } pre = u; u = u->child[s[i] - 'a']; }pre->child[s[len-1]-'a'] = NULL; removeT(u); } char s[55], Cmmd[52]; int main(){ int n; while(scanf("%d", &n) != EOF){ root = addN();root->cnt = 0; for(int i=0; i < n; i++){ scanf("%s %s", Cmmd, s); if(Cmmd[0] == 'i') inSert(s); else if(Cmmd[0] == 's'){ if(findS(s) > 0) printf("Yes\n"); else printf("No\n"); } else{ deleteS(s); } } removeT(root); } return 0; }