using System; using System.Collections.Generic; using System.IO; namespace D02._2 { class Program { static void Main(string[] args) { if (args.Length < 1) throw new ArgumentException(); if (File.Exists(args[0]) == false) throw new FileNotFoundException(); string NUL = null; var inputs = new string[5,5] { { NUL, NUL, "1", NUL, NUL }, { NUL, "2", "3", "4", NUL }, { "5", "6", "7", "8", "9" }, { NUL, "A", "B", "C", NUL }, { NUL, NUL, "D", NUL, NUL }, }; (int x, int y) finger = (0, 2); string answer = ""; using (var file = File.OpenText(args[0])) { while (true) { var line = file.ReadLine(); if (line == null) break; foreach (char c in line) { (int x, int y) = finger; switch (c) { case 'U': y--; break; case 'D': y++; break; case 'L': x--; break; case 'R': x++; break; } if (y < 0) y = 0; if (y > 4) y = 4; if (x < 0) x = 0; if (x > 4) x = 4; if (inputs[y, x] == NUL) (x, y) = finger; finger = (x, y); } answer += inputs[finger.y, finger.x]; } } Console.WriteLine($"The answer is : {answer}"); } } }