Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Scrooge_McDuck
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int[] size = new int[2];
  11. size = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  12. int n = size[0];
  13. int m = size[1];
  14. int currow = 0;
  15. int curcol = 0;
  16. int[] linearr = new int[m];
  17. int[,] arr = new int[n, m];
  18. int counter = 0;
  19. int max = 0;
  20. int left = 0, right = 0, up = 0, down = 0;
  21. for (int row = 0; row < arr.GetLength(0); row++)
  22. {
  23. linearr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  24. for (int col = 0; col < arr.GetLength(1); col++)
  25. {
  26. arr[row, col] = linearr[col];
  27. if (arr[row, col] == 0)
  28. {
  29. currow = row;
  30. curcol = col;
  31. }
  32. }
  33. }
  34. while (true)
  35. {
  36. if (curcol != 0)
  37. left = arr[currow, curcol - 1];
  38. else
  39. left = 0;
  40. if (curcol != m - 1)
  41. right = arr[currow, curcol + 1];
  42. else
  43. right = 0;
  44. if (currow != 0)
  45. up = arr[currow - 1, curcol];
  46. else
  47. up = 0;
  48. if (currow != n - 1)
  49. down = arr[currow + 1, curcol];
  50. else
  51. down = 0;
  52. if (left == 0 && right == 0 && up == 0 && down == 0)
  53. break;
  54. if (left >= right && left >= up && left >= down)
  55. max = 1;
  56. else if (right >= up && right >= down)
  57. max = 2;
  58. else if (up >= down)
  59. max = 3;
  60. else
  61. max = 4;
  62. //max = 1
  63. //position =>left
  64.  
  65. //max = 2
  66. //position =>right
  67.  
  68. //max = 3
  69. //position =>up
  70.  
  71. //max = 4
  72. //position =>down
  73. if (max == 1)
  74. {
  75. arr[currow, curcol - 1]--;
  76. curcol--;
  77. counter++;
  78. }
  79. else if (max == 2)
  80. {
  81. arr[currow, curcol + 1]--;
  82. curcol++;
  83. counter++;
  84. }
  85. else if (max == 3)
  86. {
  87. arr[currow - 1, curcol]--;
  88. currow--;
  89. counter++;
  90. }
  91. else if (max == 4)
  92. {
  93. arr[currow + 1, curcol]--;
  94. currow++;
  95. counter++;
  96. }
  97. }
  98. Console.WriteLine(counter);
  99. }
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement