#include #include struct Node { struct Node *br[26]; int num; }; Node *head; int cnt; void Tree_insert(char str[])//插入单词 { Node *t,*s=head; int i,j; int len=strlen(str); for(i=0;ibr[id]==NULL) { t=new Node; for(j=0;j<26;j++) { t->br[j]=NULL; } t->num=0; s->br[id]=t; } s=s->br[id]; s->num++; } } int Tree_Find(char str[]) { Node *s=head; int count,i; int len=strlen(str); for(i=0;ibr[id]==NULL) { return 0; } else { s=s->br[id]; count=s->num; //if (count == 0) return 0; } } return count; } void Tree_Del(char str[]) { Node *s=head; int i, id; int len=strlen(str); for(i=0;ibr[id]==NULL) { return; } else { s->num -= cnt; s=s->br[id]; } } s->num = 0; for (int i = 0; i < 26; ++i) s->br[i] = NULL; } int main() { int i; head=new Node; for(i=0;i<26;i++) { head->br[i]=NULL; head->num=0; } int n; scanf("%d", &n); char op[20], s[50]; while (n--) { scanf("%s%s", op, s); if (!strcmp(op, "insert")) Tree_insert(s); else if (!strcmp(op, "delete")) { cnt = Tree_Find(s); if (cnt <= 0) continue; Tree_Del(s); } else { if (Tree_Find(s) > 0) puts("Yes"); else puts("No"); } } return 0; }