Program.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.IO;
  3. namespace D01._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. string input = File.ReadAllText(args[0]);
  12. (int x, int y, int r) coord = (0, 0, 0);
  13. foreach (var i in input.Split(", "))
  14. {
  15. int n = int.Parse(i.Substring(1));
  16. switch (i[0])
  17. {
  18. case 'R': coord.r += 90; break;
  19. case 'L': coord.r -= 90; break;
  20. }
  21. if (coord.r < 0) coord.r += 360;
  22. if (coord.r >= 360) coord.r -= 360;
  23. switch (coord.r)
  24. {
  25. case 0: coord.y -= n; break;
  26. case 90: coord.x += n; break;
  27. case 180: coord.y += n; break;
  28. case 270: coord.x -= n; break;
  29. }
  30. }
  31. var manhattan = Math.Abs(coord.x) + Math.Abs(coord.y);
  32. Console.WriteLine($"Distance is : {manhattan}");
  33. }
  34. }
  35. }