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