diff options
| author | omagdy7 <omar.professional8777@gmail.com> | 2022-12-06 15:44:07 +0200 |
|---|---|---|
| committer | omagdy7 <omar.professional8777@gmail.com> | 2022-12-06 15:44:07 +0200 |
| commit | de0fc65843858effd3b418f228af4c2f327494d5 (patch) | |
| tree | cf4510fb0fa0e8a089764f5b0fe517200039de7c /2022/Cpp/Day6/main.cpp | |
| parent | db39b5079219af288986a9c12b0bdd5c87a5a16a (diff) | |
| download | aoc-de0fc65843858effd3b418f228af4c2f327494d5.tar.xz aoc-de0fc65843858effd3b418f228af4c2f327494d5.zip | |
Day6 done in Cpp
Diffstat (limited to '2022/Cpp/Day6/main.cpp')
| -rw-r--r-- | 2022/Cpp/Day6/main.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/2022/Cpp/Day6/main.cpp b/2022/Cpp/Day6/main.cpp new file mode 100644 index 0000000..6d45b6b --- /dev/null +++ b/2022/Cpp/Day6/main.cpp @@ -0,0 +1,24 @@ +#include <bits/stdc++.h> +using namespace std; + +int solve(int window) { + string s; + cin >> s; + for (int i = 0; i < s.size() - window; i++) { + set<char> st; + for (int j = i; j < i + window; j++) { + st.insert(s[j]); + } + if (st.size() == window) { + return i + window; + } + } + return -1; +} + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout << "Part1: " << solve(4); + // cout << "Part2: " << solve(14); +} |
