Program.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. namespace D11._1
  3. {
  4. class Program
  5. {
  6. static void Main(string[] args)
  7. {
  8. if (args.Length == 0) return;
  9. int serial = int.Parse(args[0]);
  10. const int length = 300;
  11. var grid = new int[length, length];
  12. for (int x = 1; x <= length; ++x)
  13. {
  14. for (int y = 1; y <= length; ++y)
  15. {
  16. int id = (x + 10);
  17. int n = (id * y + serial) * id;
  18. int c = (n / 100) % 10;
  19. grid[x - 1, y - 1] = c - 5;
  20. }
  21. }
  22. int maxTotal = 0;
  23. (int x, int y)? maxCoordinates = null;
  24. for (int x = 1; x <= length - 2; ++x)
  25. {
  26. for (int y = 1; y <= length - 2; ++y)
  27. {
  28. int total = 0;
  29. for (int j = 0; j < 3; ++j)
  30. for (int i = 0; i < 3; ++i)
  31. total += grid[x - 1 + i, y - 1 + j];
  32. if (total > maxTotal)
  33. {
  34. maxTotal = total;
  35. maxCoordinates = (x, y);
  36. }
  37. }
  38. }
  39. Console.WriteLine($"The answer is : ({maxCoordinates.Value.x},{maxCoordinates.Value.y})");
  40. }
  41. }
  42. }