From 6bb7b68394ebebbc69e76bee59e9351386115453 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 14 Dec 2025 21:56:30 +0200 Subject: feat(Week11): Add solutions --- Week11/Exercise13.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Week11/Exercise13.cpp (limited to 'Week11/Exercise13.cpp') diff --git a/Week11/Exercise13.cpp b/Week11/Exercise13.cpp new file mode 100644 index 0000000..ee7f57f --- /dev/null +++ b/Week11/Exercise13.cpp @@ -0,0 +1,42 @@ +#include + +unsigned fnvHash(const char* str) { + unsigned hash = 2166136261; + while (*str != '\0') { + hash *= 16777619; + hash ^= *str; + str++; + } + return hash; +} + +int main() { + unsigned allocated = 8, size = 0; + char* sentence = new char[allocated]; + + char curr; + std::cin.get(curr); + while (curr != '\n') { + sentence[size++] = curr; + std::cin.get(curr); + + // Реоразмеряване + if (size >= allocated) { + allocated *= 2; + char* newSentenceArray = new char[allocated]; + + for (unsigned i = 0; i < size; i++) + newSentenceArray[i] = sentence[i]; + + delete[] sentence; + sentence = newSentenceArray; + } + } + sentence[size] = '\0'; + + std::cout << fnvHash(sentence) << std::endl; + + delete[] sentence; + + return 0; +} -- cgit v1.3.1-23-gd82d