#include #include #include #include using namespace std; char op[10], word[50]; struct Node { int v; Node *next[26]; Node() { v = 0; for (int i = 0; i <= 25; ++i) next[i] = NULL; } } root; void Myinsert() { int len = strlen(word); Node *p = &root; for (int i = 0; i <= len - 1; ++i) { int id = word[i] - 'a'; if (p->next[id] == NULL) { p->next[id] = (Node*) malloc(sizeof(Node)); for (int j = 0; j <= 25; j++) p->next[id]->next[j] = NULL; p->next[id]->v = 0; } p = p->next[id]; p->v++; } } bool Mysearch() { int len = strlen(word); Node *p = &root; for (int i = 0; i <= len - 1; i++) { int id = word[i] - 'a'; if (p->next[id] == NULL || p->next[id]->v == 0) return false; p = p->next[id]; } return true; } void freetree(Node *p) { for (int i = 0; i <= 25; i++) if (p->next[i] != NULL) freetree(p->next[i]); free(p); } void Mydelete() { int deleteValue, len = strlen(word); Node *p = &root; for (int i = 0; i <= len - 1; i++) { int id = word[i] - 'a'; if (p->next[id] == NULL || p->next[id]->v == 0) return; p = p->next[id]; } deleteValue = p->v; p = &root; for (int i = 0; i <= len - 1; i++) { int id = word[i] - 'a'; p = p->next[id]; p->v -= deleteValue; } for (int i = 0; i <= 25; i++) if (p->next[i] != NULL) { freetree(p->next[i]); p->next[i] = NULL; } } int main() { int T; cin >> T; while (T--) { scanf("%s %s", op, word); if (op[0] == 'i') Myinsert(); else if (op[0] == 'd') Mydelete(); else if (Mysearch()) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }