diff options
author | Franciszek Malinka <franciszek.malinka@gmail.com> | 2021-10-05 21:49:54 +0200 |
---|---|---|
committer | Franciszek Malinka <franciszek.malinka@gmail.com> | 2021-10-05 21:49:54 +0200 |
commit | c5fcf7179a83ef65c86c6a4a390029149e518649 (patch) | |
tree | d29ffc5b86a0d257453cedcf87d91a13d8bf3b0d /Semestr 3/pf/lista7/zaj.cpp | |
parent | f8a88b6a4aba1f66d04711a9330eaba49a50c463 (diff) |
Duzy commit ze smieciami
Diffstat (limited to 'Semestr 3/pf/lista7/zaj.cpp')
-rw-r--r-- | Semestr 3/pf/lista7/zaj.cpp | 80 |
1 files changed, 0 insertions, 80 deletions
diff --git a/Semestr 3/pf/lista7/zaj.cpp b/Semestr 3/pf/lista7/zaj.cpp deleted file mode 100644 index 403754f..0000000 --- a/Semestr 3/pf/lista7/zaj.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include <bits/stdc++.h> -using namespace std; - -const int ALPHABET_SIZE = 26; - -struct node -{ - node *children[ALPHABET_SIZE]; - int cnt; - bool is_end; - - node() - { - for (int i = 0; i < ALPHABET_SIZE; i++) - children[i] = nullptr; - is_end = false; - cnt = 0; - } -}; - -struct TRIE -{ - node *root; - - TRIE() - { - root = new node; - } - - // dodaje słowo do słownika - void add_word(string word) - { - node *crawl = root; - for (auto c : word) - { - int letter = c - 'a'; - if (crawl->children[letter] == nullptr) - { - crawl->children[letter] = new node; - } - crawl = crawl->children[letter]; - } - crawl->is_end = true; - } - - // sprawdź czy słowo jest w słowniku - bool find(string word) - { - node *crawl = root; - for (auto c : word) - { - int letter = c - 'a'; - if (crawl->children[letter] == nullptr) - return false; - crawl = crawl->children[letter]; - } - return crawl->is_end; - } - - // usuń słowo ze słownika - void erase(string word) {} -}; - -int main() -{ - TRIE dictionary; - int q; - cin >> q; - while (q--) - { - char c; - string s; - cin >> c >> s; - if (c == 'A') - dictionary.add_word(s); - else - cout << (dictionary.find(s) ? "TAK" : "NIE") - << "\n"; - } -}
\ No newline at end of file |