Program.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. namespace D02._2
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. if (args.Length < 1) throw new ArgumentException();
  11. if (File.Exists(args[0]) == false) throw new FileNotFoundException();
  12. string NUL = null;
  13. var inputs = new string[5,5] {
  14. { NUL, NUL, "1", NUL, NUL },
  15. { NUL, "2", "3", "4", NUL },
  16. { "5", "6", "7", "8", "9" },
  17. { NUL, "A", "B", "C", NUL },
  18. { NUL, NUL, "D", NUL, NUL },
  19. };
  20. (int x, int y) finger = (0, 2);
  21. string answer = "";
  22. using (var file = File.OpenText(args[0]))
  23. {
  24. while (true)
  25. {
  26. var line = file.ReadLine();
  27. if (line == null) break;
  28. foreach (char c in line)
  29. {
  30. (int x, int y) = finger;
  31. switch (c)
  32. {
  33. case 'U': y--; break;
  34. case 'D': y++; break;
  35. case 'L': x--; break;
  36. case 'R': x++; break;
  37. }
  38. if (y < 0) y = 0;
  39. if (y > 4) y = 4;
  40. if (x < 0) x = 0;
  41. if (x > 4) x = 4;
  42. if (inputs[y, x] == NUL) (x, y) = finger;
  43. finger = (x, y);
  44. }
  45. answer += inputs[finger.y, finger.x];
  46. }
  47. }
  48. Console.WriteLine($"The answer is : {answer}");
  49. }
  50. }
  51. }