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 5.70 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace judgeMatrix
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int[] size = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  11. int rowsInput = size[0];
  12. int colsInput = size[1];
  13. int[,] matrix = new int[rowsInput,colsInput];
  14. int currentRow = 0;
  15. int currentCol = 0;
  16. int money = 0;
  17. int left = 0;
  18. int right = 0;
  19. int down = 0;
  20. int up = 0;
  21.  
  22. for (int rows = 0; rows < rowsInput; rows++)
  23. {
  24. int[] input = new int[colsInput];
  25. input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  26.  
  27. for (int cols = 0; cols < colsInput; cols++)
  28. {
  29. matrix[rows, cols] = input[cols];
  30.  
  31. if (matrix[rows,cols] == 0)
  32. {
  33. currentRow = rows;
  34. currentCol = cols;
  35. }
  36. }
  37. }
  38. //MatrinPrint(rowsInput,colsInput,matrix);
  39.  
  40. while (true)
  41. {
  42. if (currentRow != 0)
  43. {
  44. up = matrix[currentRow - 1, currentCol];
  45. }
  46. else
  47. {
  48. up = 0;
  49. }
  50. if (currentRow != rowsInput-1)
  51. {
  52. down = matrix[currentRow + 1, currentCol];
  53. }
  54. else
  55. {
  56. down = 0;
  57. }
  58. if (currentCol != 0 )
  59. {
  60. left = matrix[currentRow, currentCol - 1];
  61. }
  62. else
  63. {
  64. left = 0;
  65. }
  66. if (currentCol != colsInput -1)
  67. {
  68. right = matrix[currentRow, currentCol +1];
  69. }
  70. else
  71. {
  72. right = 0;
  73. }
  74.  
  75. if (right == 0 && left==0 && up == 0 && down ==0)
  76. {
  77. break;
  78. }
  79.  
  80. if (left >= right && left >= up && left >= down)
  81. {
  82. currentCol = currentCol - 1;
  83. matrix[currentRow, currentCol] = matrix[currentRow, currentCol] - 1;
  84. money++;
  85. }
  86. else if (right >= up && right >= down)
  87. {
  88. currentCol = currentCol + 1;
  89. matrix[currentRow, currentCol] = matrix[currentRow, currentCol] - 1;
  90. money++;
  91. }
  92. else if (up >=down)
  93. {
  94. currentRow = currentRow - 1;
  95. matrix[currentRow, currentCol] = matrix[currentRow, currentCol] - 1;
  96. money++;
  97. }
  98. else
  99. {
  100. currentRow = currentRow + 1;
  101. matrix[currentRow, currentCol] = matrix[currentRow, currentCol] - 1;
  102. money++;
  103. }
  104. /*
  105. if (right == left && right == down && right == up)
  106. {
  107. currentCol = currentCol - 1;
  108. matrix[currentRow, currentCol] = matrix[currentRow, currentCol] - 1;
  109. money++;
  110. }
  111. if (left == up && left == down)
  112. {
  113. currentCol = currentCol + 1;
  114. matrix[currentRow, currentCol] = matrix[currentRow, currentCol] - 1;
  115. money++;
  116. }
  117. if (up == down)
  118. {
  119. currentRow = currentRow - 1;
  120. matrix[currentRow, currentCol] = matrix[currentRow, currentCol] - 1;
  121. money++;
  122. }
  123.  
  124. if (up > down && left > right)
  125. {
  126. currentRow = currentRow - 1;
  127. currentCol = currentCol - 1;
  128. matrix[currentRow, currentCol] = matrix[currentRow, currentCol] - 1;
  129. money++;
  130. }
  131. if (up > down && left < right)
  132. {
  133. currentRow = currentRow - 1;
  134. currentCol = currentCol + 1;
  135. matrix[currentRow, currentCol] = matrix[currentRow, currentCol] - 1;
  136. money++;
  137. }
  138. if (up < down && left > right)
  139. {
  140. currentRow = currentRow + 1;
  141. currentCol = currentCol - 1;
  142. matrix[currentRow, currentCol] = matrix[currentRow, currentCol] - 1;
  143. money++;
  144. }
  145. if (up < down && left < right)
  146. {
  147. currentRow = currentRow + 1;
  148. currentCol = currentCol + 1;
  149. matrix[currentRow, currentCol] = matrix[currentRow, currentCol] - 1;
  150. money++;
  151. }
  152. */
  153. }
  154. Console.WriteLine(money);
  155. }
  156.  
  157. private static void MatrinPrint(int lenOfRows, int lenOfCols, int[,] matrix)
  158. {
  159. for (int rows = 0; rows < lenOfRows; rows++)
  160. {
  161. for (int cols = 0; cols < lenOfCols; cols++)
  162. {
  163. Console.Write(matrix[rows,cols]+ " ");
  164. }
  165. Console.WriteLine();
  166. }
  167. }
  168. }
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement