/*D #include #include #include #include using namespace std; const int N = 1e6 + 10; const int x = 123; struct Str { char s[50]; }; Str str[N]; unsigned long long xp[50], H[50]; multiset ms; void init() { xp[0] = 1; for(int i = 1; i < 50; ++i) xp[i] = xp[i - 1] * x; } int main() { //freopen("in.txt", "r", stdin); int n; scanf("%d", &n); ms.clear(); init(); for(int i = 0; i < n; ++i) { scanf("%s", str[i].s); int len = strlen(str[i].s); sort(str[i].s, str[i].s + len); H[len] = 0; for(int j = len - 1; j >= 0; --j) H[j] = H[j + 1] * x + str[i].s[j]; unsigned long long h = H[0] - H[len] * xp[len]; printf("%d\n", ms.count(h)); ms.insert(h); } return 0; } */ /*A #include #include #include #include using namespace std; const int N = 1e5 + 10; char s[N]; int H[N]; int powm(int a, int b) { int ans = 1; while(b) { if(b & 1) ans = ans * a % 9973; a = a * a % 9973; b >>= 1; } return ans; } int main() { // freopen("in.txt", "r", stdin); int n; while(~scanf("%d", &n)) { scanf("%s", s + 1); int len = strlen(s + 1); H[0] = 1; for(int i = 1; i <= len; ++i) H[i] = (H[i - 1] * (s[i] - 28)) % 9973; H[0] = 0; while(n --) { int a, b; scanf("%d%d", &a, &b); if(a == 1) printf("%d\n", H[b]); else printf("%d\n", (H[b] * powm(H[a - 1], 9971)) % 9973); } } return 0; } */ #include #include #include #include #include #include #include using namespace std; const int MAXS = 100005; typedef struct node{ char c; node* next[26]; int num; }*pnode; pnode root; char s[50]; void init(pnode &p) { for(int i = 0; i < 26; ++i) p->next[i] = 0; p->num = 0; } void _insert(char *s) { pnode p = root, t; int len = strlen(s); for(int i = 0; i < len; ++i) { if(p->next[s[i] - 97] == NULL) { t = new node; init(t); t->c = s[i]; p->next[s[i] - 97] = t; } p = p->next[s[i] - 97]; p->num++; } } int _search(char *s) { pnode p = root; int len = strlen(s); for(int i = 0; i < len; ++i) { if(p->next[s[i] - 97] == NULL) return 0; p = p->next[s[i] - 97]; } return p->num > 0; } void _delete(char *s) { pnode p = root; int len = strlen(s), cnt; for(int i = 0; i < len; ++i) { if(p->next[s[i] - 97] == NULL) return ; p = p->next[s[i] - 97]; } cnt = p->num; for(int i = 0; i < 26; ++i) p->next[i] = NULL; p = root; for(int i = 0; i < len; ++i) { p = p->next[s[i] - 97]; p->num -= cnt; } } int main() { // freopen("in.txt", "r", stdin); root = new node; init(root); int n; scanf("%d", &n); while(n --) { char op[10]; scanf("%s%s", op, s); if(strcmp(op, "insert") == 0) _insert(s); else if(strcmp(op, "delete") == 0) _delete(s); else { if(_search(s)) puts("Yes"); else puts("No"); } } return 0; }