summaryrefslogtreecommitdiffstats
path: root/02-data_structures/03-hash_tables/03-hash_substring/hash_substring.cpp
diff options
context:
space:
mode:
Diffstat (limited to '02-data_structures/03-hash_tables/03-hash_substring/hash_substring.cpp')
-rw-r--r--02-data_structures/03-hash_tables/03-hash_substring/hash_substring.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/02-data_structures/03-hash_tables/03-hash_substring/hash_substring.cpp b/02-data_structures/03-hash_tables/03-hash_substring/hash_substring.cpp
new file mode 100644
index 0000000..3a3680a
--- /dev/null
+++ b/02-data_structures/03-hash_tables/03-hash_substring/hash_substring.cpp
@@ -0,0 +1,38 @@
+#include <iostream>
+#include <string>
+#include <vector>
+
+using std::string;
+typedef unsigned long long ull;
+
+struct Data {
+ string pattern, text;
+};
+
+Data read_input() {
+ Data data;
+ std::cin >> data.pattern >> data.text;
+ return data;
+}
+
+void print_occurrences(const std::vector<int>& output) {
+ for (size_t i = 0; i < output.size(); ++i)
+ std::cout << output[i] << " ";
+ std::cout << "\n";
+}
+
+std::vector<int> get_occurrences(const Data& input) {
+ const string& s = input.pattern, t = input.text;
+ std::vector<int> ans;
+ for (size_t i = 0; i + s.size() <= t.size(); ++i)
+ if (t.substr(i, s.size()) == s)
+ ans.push_back(i);
+ return ans;
+}
+
+
+int main() {
+ std::ios_base::sync_with_stdio(false);
+ print_occurrences(get_occurrences(read_input()));
+ return 0;
+}