Program.cs 1.4 KB

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