From 038dc026fc7a01bef984918caac894ca90bff36b Mon Sep 17 00:00:00 2001 From: MD Date: Sat, 7 Sep 2024 18:41:49 -0700 Subject: [PATCH] 20240907 md's submission for cf858d (#6477) --- .../09/0907/personal_submission/cf858d_md.cpp | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 daily_problems/2024/09/0907/personal_submission/cf858d_md.cpp diff --git a/daily_problems/2024/09/0907/personal_submission/cf858d_md.cpp b/daily_problems/2024/09/0907/personal_submission/cf858d_md.cpp new file mode 100644 index 0000000000..d14a09590f --- /dev/null +++ b/daily_problems/2024/09/0907/personal_submission/cf858d_md.cpp @@ -0,0 +1,42 @@ +// 0907 +#include + +int main() { + std::ios::sync_with_stdio(false); + std::cin.tie(nullptr); + + int n; + std::cin >> n; + std::vector nums(n); + std::vector> hash(n); + std::map cnt; + for (int i = 0; i < n; ++i) { + std::cin >> nums[i]; + for (int len = 1; len <= 9; ++len) { + std::set patterns; + + for (int left = 0; left + len <= 9; ++left) { + std::string sub = nums[i].substr(left, len); + patterns.insert(sub); + } + + for (auto pattern : patterns) { + hash[i].push_back(pattern); + cnt[pattern]++; + } + } + + } + + for (int i = 0; i < n; ++i) { + for (auto& sub : hash[i]) { + if (cnt[sub] == 1) { + std::cout << sub << '\n'; + break; + } + } + } + + + return 0; +} \ No newline at end of file