Program.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. namespace D03._1
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. if (args.Length < 1) throw new ArgumentException();
  11. if (File.Exists(args[0]) == false) throw new FileNotFoundException();
  12. string text = "";
  13. using (var file = File.OpenText(args[0]))
  14. {
  15. text = file.ReadToEnd();
  16. }
  17. (int x, int y) pos = (0, 0);
  18. var visited = new HashSet<(int, int)>
  19. {
  20. pos
  21. };
  22. foreach (var c in text)
  23. {
  24. switch (c)
  25. {
  26. case '>': pos.x++; break;
  27. case '<': pos.x--; break;
  28. case '^': pos.y--; break;
  29. case 'v': case 'V': pos.y++; break;
  30. default: continue;
  31. }
  32. visited.Add(pos);
  33. }
  34. Console.WriteLine($"Answer is : {visited.Count}");
  35. }
  36. }
  37. }