Skip to content

Commit

Permalink
20240907 md's submission for cf858d (#6477)
Browse files Browse the repository at this point in the history
  • Loading branch information
mengdiwang authored Sep 8, 2024
1 parent e854147 commit 038dc02
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions daily_problems/2024/09/0907/personal_submission/cf858d_md.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 0907
#include <bits/stdc++.h>

int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);

int n;
std::cin >> n;
std::vector<std::string> nums(n);
std::vector<std::vector<std::string>> hash(n);
std::map<std::string, int> cnt;
for (int i = 0; i < n; ++i) {
std::cin >> nums[i];
for (int len = 1; len <= 9; ++len) {
std::set<std::string> 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;
}

0 comments on commit 038dc02

Please sign in to comment.