#include #include using namespace std; char cmd[10], str[40]; struct Node { int cnt; Node* son[26]; }; Node* root; void insert(char* str) { int len = strlen(str); Node* t = root; t->cnt++; for (int i = 0; i < len; i++) { int j = str[i] - 'a'; if (t->son[j] == NULL) { t->son[j] = new Node(); } t = t->son[j]; t->cnt++; } } void remove(char* str) { int len = strlen(str); Node* t = root; int diff = 0; for (int i = 0; i < len; i++) { int j = str[i] - 'a'; if (t->son[j] == NULL) { return; } if (i == len - 1) { diff = t->son[j]->cnt; t->son[j] = NULL; } else { t = t->son[j]; } } t = root; t->cnt -= diff; for (int i = 0; i < len; i++) { int j = str[i] - 'a'; if (t->son[j] == NULL) { return; } t = t->son[j]; t->cnt -= diff; } } bool search(char* str) { int len = strlen(str); Node* t = root; for (int i = 0; i < len; i++) { int j = str[i] - 'a'; if (t->son[j] == NULL) { return false; } t = t->son[j]; } return (t->cnt > 0); } int main() { root = new Node(); int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%s%s", cmd, str); if (strcmp(cmd, "insert") == 0) { insert(str); } else if (strcmp(cmd, "delete") == 0) { remove(str); } else if (strcmp(cmd, "search") == 0) { bool find = search(str); if (find) { printf("Yes\n"); } else { printf("No\n"); } } } }