diff options
-rw-r--r-- | 22.6/main.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/22.6/main.cpp b/22.6/main.cpp new file mode 100644 index 0000000..e7eee34 --- /dev/null +++ b/22.6/main.cpp @@ -0,0 +1,32 @@ +#include <iostream> +#include <algorithm> +#include <string> +using namespace std; + +int +part1(string signal, int target) +{ + constexpr int amt = 'z' - 'a' + 1; + int last[amt]; + int last_rep = -1; + fill(begin(last), end(last), -10); + for (int i = 0; i < signal.length(); i++) { + int c = signal[i] - 'a'; + if (c >= amt) throw "bad input"; + last_rep = max(last_rep, last[c]); + if (i - last_rep >= target) { + return i + 1; + } + last[c] = i; + } + return -1; +} + +int +main() +{ + for (string line; getline(cin, line); ) { + cout << part1(line, 4) << endl; + cout << part1(line, 14) << endl; + } +} |