1
0

Program.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. namespace D11._2
  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, int g)? maxCoordinates = null;
  24. for (var g = 0; g < length; ++g)
  25. {
  26. for (int x = 1; x <= length -g + 1; ++x)
  27. for (int y = 1; y <= length -g + 1; ++y)
  28. {
  29. int total = 0;
  30. for (int j = 0; j < g; ++j)
  31. for (int i = 0; i < g; ++i)
  32. {
  33. total += grid[x - 1 + i, y - 1 + j];
  34. }
  35. if (total > maxTotal)
  36. {
  37. maxTotal = total;
  38. maxCoordinates = (x, y, g);
  39. }
  40. }
  41. }
  42. Console.WriteLine($"The answer is : ({maxCoordinates.Value.x},{maxCoordinates.Value.y},{maxCoordinates.Value.g})");
  43. }
  44. }
  45. }