problem Description
The bear has a magical dictionary, you can do the following three operations in it:
1、insert : 往神奇字典中插入一个单词2、delete: 在神奇字典中删除所有前缀等于给定字符串的单词3、search: 查询是否在神奇字典中有一个字符串的前缀等于给定的字符串
Input
There is only one set of test data here. The first line enters a positive integer n (1\leq n\leq 100000) n< Span class= "Mopen" > (1≤n≤< Span class= "Mord" >10000 0n< Span class= "katex-html" >< Span class= "Mord mathit" >n lines, each containing two strings, separated by a space in the middle. The first string represents the associated action (including: INSERT, delete, or search). The second string represents the string specified after the related operation, and the second string is no longer than 30. The second string is made up of lowercase letters only.
Output
For each search operation, if a word with the given string prefix is present in the degree bear's dictionary, output yes or output No.
Sample Input
5insert helloinsert hehesearch hdelete hesearch Hello
Sample OutputCopy
YesNo
The operation of the dictionary tree-template has added a DELETE statement
1#include <stdio.h>2 //#include <bits/stdc++.h>3#include <string.h>4#include <iostream>5#include <math.h>6#include <sstream>7#include <Set>8#include <queue>9#include <map>Ten#include <vector> One#include <algorithm> A#include <limits.h> - #defineINF 0x7fffffff - #defineINFL 0X7FFFFFFFFFFFFFFF the #defineLson l,m,rt<<1 - #defineRson m+1,r,rt<<1|1 - #defineLL Long Long - #defineULL unsigned long Long + using namespacestd; - +typedefstructtrie{ A intv; atTrie *next[ -]; - }trie; - Trie Root; - voidCreatetrie (Char*str) - { - intLen =strlen (str); inTrie *p = &root, *Q; - for(intI=0; i<len; ++i) to { + intid = str[i]-'a'; - if(P->next[id] = =NULL) the { *Q = (Trie *)malloc(sizeof(root)); $Q->v =1;Panax Notoginseng for(intj=0; j< -; ++j) -Q->NEXT[J] =NULL; theP->next[id] =Q; +p = p->Next[id]; A } the Else + { -p->next[id]->v++; $p = p->Next[id]; $ } - } - } the - intFindtrie (Char*str)Wuyi { the intLen =strlen (str); -Trie *p = &Root; Wu for(intI=0; i<len; ++i) - { About intid = str[i]-'a'; $p = p->Next[id]; - if(p = =NULL) - return 0; - } A returnP->v; + } the voidDeleChar*STR,intN) - { $Trie *p = &Root; the intLen =strlen (str); the for(intI=0; i<len; ++i) the { the intid = str[i]-'a'; -p = p->Next[id]; inp->v-=N; the } the for(intj=0; j< -; ++j) About { theP->NEXT[J] =NULL; the } the } + intMain () - { the intT;Bayi Chars1[10000],s2[10000]; the for(intI=0;i< -; i++) the { -root.next[i]=NULL; - } theCin>>T; the while(t--) the { thescanf"%s%s", S1,S2); - if(s1[0]=='I') the { the Createtrie (S2); the }94 Else if(s1[0]=='s') the { the intans=Findtrie (S2); the if(ANS)98 { AboutPuts"Yes"); - }101 Else102 {103Puts"No");104 } the }106 Else107 {108 intCnt=Findtrie (S2);109 if(CNT) the {111 Dele (s2,cnt); the }113 } the } the return 0; the}
2016 "Baidu Star"-Qualifying race (Astar Round1) C