/* * File: main.cpp * Author: semprathlon * * Created on May 15, 2016, 10:44 AM */ #include #include #include #include #include using namespace std; const int maxn = 50; struct Trie { int cnt; Trie* child[26]; Trie() { for (int i = 0; i < 26; i++) child[i] = NULL; cnt = 0; } void insert(char* s, int len, int p) { int ch = s[p] - 'a'; if (child[ch] == NULL) child[ch] = new Trie(); child[ch]->cnt++; // cout<cnt<insert(s, len, p + 1); } int query(char* s, int len, int p) { int ch = s[p] - 'a'; if (p > len - 1 ) return -1; if (child[ch] == NULL|| child[ch]->cnt < 1) return -2; // cout<cnt<query(s, len, p + 1); return tmp>-2?max(tmp,p):-2; } int del(char* s, int len, int p) { int ch = s[p] - 'a'; if (p > len - 1 || child[ch] == NULL) return 0; int res = child[ch]->del(s, len, p + 1); if (p == len - 1) { if (child[ch] != NULL) { res = child[ch]->cnt; } } if (child[ch] != NULL) { child[ch]->cnt -= res; if (child[ch]->cnt < 1) { free(child[ch]); child[ch] = NULL; } } return res; } } *tr; char str[maxn], op[maxn]; int main(int argc, char** argv) { int n; scanf("%d", &n); tr = new Trie(); while (n--) { scanf("%s%s", op, str); if (op[0] == 'i') { tr->insert(str, strlen(str), 0); } else if (op[0] == 's') { puts(tr->query(str, strlen(str), 0) >= 0 ? "Yes" : "No"); // cout<query(str, strlen(str), 0)<del(str, strlen(str), 0); } } free(tr); return 0; }