| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #include <string>
- #include <iostream>
- #include "cached_shortest_sequences.h"
- #include "segmented_sequences.h"
- #include "keypad_funcs.h"
- #include "convert_code.h"
- #include "input.h"
- int main(int argc, char **argv) {
- std::string input_text = ReadFile(argv[1]);
- Lines lines(input_text);
- CachedShortestSequences cached_shortest_sequences;
- std::vector<std::string> codes;
- for (;;) {
- auto line = lines.Next();
- if (!line || line->empty()) {
- break;
- }
- codes.emplace_back(line->data(), line->size());
- }
- std::vector<char> buffer;
- size_t total = 0;
- for (const auto &code : codes) {
- size_t converted_code = ConvertCode(code);
- auto shortest_sequences0 =
- cached_shortest_sequences.Find(code, ApplyNumericCommand);
- for (size_t layer = 0; layer < 25; ++layer) {
- auto shortest_sequences1 = cached_shortest_sequences.Find(
- shortest_sequences0, ApplyDirectionalCommand);
- shortest_sequences0 = shortest_sequences1;
- }
- total += shortest_sequences0->MinSize() * converted_code;
- }
- std::cout << total << std::endl;
- return 0;
- }
|