Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
#include
#include
using namespace std; const int alphabet_size = 26; struct node { bool is_end_of_word; node * children_of_node[alphabet_size]; node() { is_end_of_word = false; for(int i = 0; i < alphabet_size; i++) { children_of_node[i] = NULL; } } }; void insert_word(node * trie, string word) { node * tmp = trie; for(int i = 0; i < (int) word.size(); i++) { int c = word[i] - 'a'; if(tmp -> children_of_node[i] == NULL) { tmp -> children_of_node[i] = new node(); } tmp = tmp -> children_of_node[i]; } tmp -> is_end_of_word = true; } bool search_word(node * trie, string word) { node * tmp = trie; for(int i = 0; i < (int) word.size(); i++) { int c = word[i] - 'a'; if(tmp -> children_of_node[i] == NULL) { return false; } tmp = tmp -> children_of_node[i]; } return tmp -> is_end_of_word; } void delete_word(node * trie, string word) { node * tmp = trie; for(int i = 0; i < (int) word.size(); i++) { int c = word[i] - 'a'; if(tmp -> children_of_node[i] == NULL) { return; } tmp = tmp -> children_of_node[i]; } tmp -> is_end_of_word = false; } int main() { ios_base::sync_with_stdio(false); node * trie = new node(); while(true) { string a, b; cin >> a >> b; if(a == "insert") { insert_word(trie, b); } else if(a == "delete") { delete_word(trie, b); } else { cout << search_word(trie, b) << endl; } } return 0; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)