| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- using System;
- using System.IO;
- namespace D01._1
- {
- class Program
- {
- static void Main(string[] args)
- {
- if (args.Length < 1) throw new ArgumentException();
- if (File.Exists(args[0]) == false) throw new FileNotFoundException();
- string input = File.ReadAllText(args[0]);
- (int x, int y, int r) coord = (0, 0, 0);
- foreach (var i in input.Split(", "))
- {
- int n = int.Parse(i.Substring(1));
- switch (i[0])
- {
- case 'R': coord.r += 90; break;
- case 'L': coord.r -= 90; break;
- }
- if (coord.r < 0) coord.r += 360;
- if (coord.r >= 360) coord.r -= 360;
- switch (coord.r)
- {
- case 0: coord.y -= n; break;
- case 90: coord.x += n; break;
- case 180: coord.y += n; break;
- case 270: coord.x -= n; break;
- }
- }
- var manhattan = Math.Abs(coord.x) + Math.Abs(coord.y);
- Console.WriteLine($"Distance is : {manhattan}");
- }
- }
- }
|