#include #include #include #include using namespace std; const int N = 30; struct Node { Node* ch[N]; int sum; }*root; int n; char s[40], tmp[20]; void Insert() { Node* p = root; int len = strlen(s); for(int i = 0; i < len; i++) { //printf("%c", s[i]); int k = s[i]-'a'; if(p->ch[k] == NULL) { Node* q = (Node*)malloc(sizeof(Node)); for(int j = 0; j < N; j++) q->ch[j] = 0; q->sum = 0; p->ch[k] = q; } p->sum++; p = p->ch[k]; } p->sum++; //printf("\n"); } void Search() { //printf("################## %s\n", s); int len = strlen(s); Node* p = root; for(int i = 0; i < len; i++) { int k = s[i]-'a'; //printf("%c", s[i]); if(p->ch[k] == NULL || p->sum == 0) {printf("No\n"); return;} p = p->ch[k]; } //printf("\n"); if(p->sum != 0) printf("Yes\n"); //if(p->sum != 0) printf("@@@@@@@@@@@%5d\n", p->sum); else printf("No\n"); } void Del(Node* p) { if(p == NULL || p->sum == 0) return; p->sum = 0; //printf("%d\n", p->sum); for(int i = 0; i < N; i++) { if(p->ch[i] != NULL) { //printf("%c", i+'a'); Del(p->ch[i]); } } } void Delete() { int len = strlen(s); Node* p = root; for(int i = 0; i < len; i++) { int k = s[i]-'a'; if(p->ch[k] == NULL) return; p = p->ch[k]; //printf("%c", k+'a'); } int sum = p->sum; Del(p); p = root; for(int i = 0; i < len; i++) { p->sum -= sum; int k = s[i]-'a'; //if(p->ch[k] == NULL) return; p = p->ch[k]; //printf("%c", k+'a'); } //p->sum -= sum; } void Work() { root = (Node*) malloc(sizeof(Node)); for(int i = 0; i < N; i++) root->ch[i] = 0; root->sum = 0; for(int i = 0; i < n; i++) { scanf("%s%s", tmp, s); if(strcmp(tmp, "insert") == 0) Insert(); else if(strcmp(tmp, "search") == 0) Search(); else if(strcmp(tmp, "delete") == 0) Delete(); } } int main() { //freopen("test.in", "r", stdin); while(~scanf("%d", &n)) { Work(); } }