#include #include #include #include using namespace std; const int N = 3000001; const int K = 26; struct Node { Node *s[K]; Node *clear() { for (int k = 0; k < K; k++) s[k] = NULL; return this; } }; int n; char ss[10], s[31]; Node a[N], *ap, *root; void insert(char *s) { for (Node *cur = root; *s != '\0'; s++) { int x = *s - 'a'; if (cur->s[x] == NULL) cur->s[x] = (ap++)->clear(); cur = cur->s[x]; } } void remove(char s[]) { Node *cur = root; stack tmp; while(!tmp.empty()) tmp.pop(); tmp.push(cur); int i = 0; for (; s[i + 1] != '\0'; i++) { int x = s[i] - 'a'; cur = cur->s[x]; if (cur == NULL) return; tmp.push(cur); } while(!tmp.empty()){ cur=tmp.top(); tmp.pop(); cur->s[s[i] - 'a'] = NULL; i--; bool son=false; for (int j=0;js[j]!=NULL) {son=true;break;} if(son) break; } } bool get(char *s) { for (Node *cur = root; *s != '\0'; s++) { int x = *s - 'a'; cur = cur->s[x]; if (cur == NULL) return false; } return true; } int main() { ap = a; root = (ap++)->clear(); scanf("%d", &n); while (n--) { scanf("%s%s", ss, s); if (strcmp(ss, "insert") == 0) { insert(s); } else if (strcmp(ss, "search") == 0) { if (get(s)) printf("Yes\n"); else printf("No\n"); } else if (strcmp(ss, "delete") == 0) { remove(s); } } return 0; }