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
#include
using namespace std; const int ALPHABET_SIZE = 36; map
alphabet; struct node { node * children_of_node[ALPHABET_SIZE]; bool is_end_of_word; node() { is_end_of_word = false; for(int i = 0; i < ALPHABET_SIZE; i++) { children_of_node[i] = NULL; } } }; void add_word(node * trie, wstring word) { node * tmp = trie; for(int i = 0; i <(int) word.length(); i++) { int c = alphabet[word[i]]; if(tmp -> children_of_node[c] == NULL) { tmp -> children_of_node[c] = new node(); } tmp = tmp -> children_of_node[c]; } tmp -> is_end_of_word = true; } bool search_word(node * trie, wstring word) { node * tmp = trie; for(int i = 0; i < (int) word.length(); i++) { int c = alphabet[word[i]]; if(tmp -> children_of_node[c] == NULL) { return false; } tmp = tmp -> children_of_node[c]; } return tmp -> is_end_of_word; } int main() { wifstream file("all.txt"); file.imbue(locale(file.getloc(), new codecvt_utf8
)); if(!file.is_open()) { cout << "Error opening file!" << endl; return 0; } locale::global(locale("mk_MK.UTF-8")); wcout.imbue(locale()); wcin.imbue(locale()); node * trie = new node(); wstring word; int r = 0; int cnt = 1; while(file >> word) { for(wchar_t c : word) { if(alphabet[c] == 0) { alphabet[c] = cnt; cnt++; } } add_word(trie, word); } wstring s; wcin >> s; cout << s.length() << endl; for(wchar_t c : s) { cout << alphabet[c] << " "; } wcout << s << endl; if(search_word(trie, s)) { wcout << "Ovoj zbor se naoga vo datotekata" << endl; } else { wcout << "Ovoj zbor ne se naoga vo datotekata" << 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)