nassss

Untitled

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