-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
20240907 md's submission for cf858d (#6477)
- Loading branch information
1 parent
e854147
commit 038dc02
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
daily_problems/2024/09/0907/personal_submission/cf858d_md.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |