main.cc 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <string>
  2. #include <iostream>
  3. #include "cached_shortest_sequences.h"
  4. #include "segmented_sequences.h"
  5. #include "keypad_funcs.h"
  6. #include "convert_code.h"
  7. #include "input.h"
  8. int main(int argc, char **argv) {
  9. std::string input_text = ReadFile(argv[1]);
  10. Lines lines(input_text);
  11. CachedShortestSequences cached_shortest_sequences;
  12. std::vector<std::string> codes;
  13. for (;;) {
  14. auto line = lines.Next();
  15. if (!line || line->empty()) {
  16. break;
  17. }
  18. codes.emplace_back(line->data(), line->size());
  19. }
  20. std::vector<char> buffer;
  21. size_t total = 0;
  22. for (const auto &code : codes) {
  23. size_t converted_code = ConvertCode(code);
  24. auto shortest_sequences0 =
  25. cached_shortest_sequences.Find(code, ApplyNumericCommand);
  26. for (size_t layer = 0; layer < 25; ++layer) {
  27. auto shortest_sequences1 = cached_shortest_sequences.Find(
  28. shortest_sequences0, ApplyDirectionalCommand);
  29. shortest_sequences0 = shortest_sequences1;
  30. }
  31. total += shortest_sequences0->MinSize() * converted_code;
  32. }
  33. std::cout << total << std::endl;
  34. return 0;
  35. }