Advertisement
svetlyoek

Untitled

May 25th, 2019
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.71 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Sneaking
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int rows = int.Parse(Console.ReadLine());
  10. int nikoladzeRow = -1;
  11. int nikoladzeCol = -1;
  12. int currentRow = -1;
  13. int currentCol = -1;
  14. char[] cols = Console.ReadLine().ToCharArray();
  15. char[,] matrix = new char[rows,cols.Length];
  16.  
  17. for (int row = 0; row < rows; row++)
  18. {
  19. for (int col = 0; col < cols.Length; col++)
  20. {
  21.  
  22. matrix[row, col] = cols[col];
  23.  
  24. if (matrix[row, col] == 'N')
  25. {
  26. nikoladzeRow = row;
  27.  
  28. nikoladzeCol = col;
  29. }
  30.  
  31. else if (matrix[row, col] == 'S')
  32. {
  33. currentRow = row;
  34.  
  35. currentCol = col;
  36. }
  37.  
  38. }
  39.  
  40. if(row<rows-1)
  41. {
  42. cols = Console.ReadLine().ToCharArray();
  43. }
  44.  
  45. }
  46.  
  47.  
  48. char[] commands = Console.ReadLine().ToCharArray();
  49.  
  50. for (int i = 0; i < commands.Length; i++)
  51. {
  52. char command = (char)commands[i];
  53.  
  54. for (int row = 0; row < matrix.GetLength(0); row++)
  55. {
  56. for (int col = 0; col < matrix.GetLength(1); col++)
  57. {
  58. if (matrix[row, col] == 'b')
  59. {
  60. if (col == matrix.GetLength(1) - 1)
  61. {
  62. matrix[row, col] = 'd';
  63. }
  64. else if (col < matrix.GetLength(1) - 1)
  65. {
  66. matrix[row, col] = '.';
  67. matrix[row, col + 1] = 'b';
  68. }
  69. if (currentRow == row && currentCol > col)
  70. {
  71. Console.WriteLine($"Sam died at {row}, {col}");
  72. matrix[row, col] = 'X';
  73. return;
  74. }
  75. }
  76.  
  77. else if (matrix[row, col] == 'd')
  78. {
  79. if (col == 0)
  80. {
  81. matrix[row, col] = 'b';
  82. }
  83. else if (col > 0)
  84. {
  85. matrix[row, col] = '.';
  86. matrix[row, col - 1] = 'd';
  87. }
  88.  
  89. if (currentRow == row && currentCol < col)
  90. {
  91. Console.WriteLine($"Sam died at {row}, {col}");
  92. matrix[row, col] = 'X';
  93. return;
  94. }
  95. }
  96. }
  97. }
  98.  
  99. if (command == 'U')
  100. {
  101. if (matrix[currentRow - 1, currentCol] == 'b' || matrix[currentRow - 1, currentCol] == 'd')
  102. {
  103. matrix[currentRow, currentCol] = '.';
  104. matrix[currentRow - 1, currentCol] = 'S';
  105. currentRow = currentRow - 1;
  106. }
  107. else
  108. {
  109. matrix[currentRow, currentCol] = '.';
  110. matrix[currentRow - 1, currentCol] = 'S';
  111. currentRow = currentRow - 1;
  112. }
  113.  
  114. if (currentRow == nikoladzeRow)
  115. {
  116. Console.WriteLine($"Nikoladze killed!");
  117. matrix[nikoladzeRow, nikoladzeCol] = 'X';
  118. return;
  119. }
  120.  
  121. }
  122.  
  123. if (command == 'D')
  124. {
  125. if (matrix[currentRow + 1, currentCol] == 'b' || matrix[currentRow + 1, currentCol] == 'd')
  126. {
  127. matrix[currentRow, currentCol] = '.';
  128. matrix[currentRow + 1, currentCol] = 'S';
  129. currentRow = currentRow + 1;
  130. }
  131. else
  132. {
  133. matrix[currentRow, currentCol] = '.';
  134. matrix[currentRow + 1, currentCol] = 'S';
  135. currentRow = currentRow + 1;
  136. }
  137.  
  138. if (currentRow == nikoladzeRow)
  139. {
  140. Console.WriteLine($"Nikoladze killed!");
  141. matrix[nikoladzeRow, nikoladzeCol] = 'X';
  142. return;
  143. }
  144.  
  145. }
  146.  
  147. if (command == 'L')
  148. {
  149. if (matrix[currentRow, currentCol - 1] == 'b' || matrix[currentRow, currentCol - 1] == 'd')
  150. {
  151. matrix[currentRow, currentCol] = '.';
  152. matrix[currentRow, currentCol - 1] = 'S';
  153. currentCol = currentCol - 1;
  154. }
  155. else
  156. {
  157. matrix[currentRow, currentCol] = '.';
  158. matrix[currentRow, currentCol - 1] = 'S';
  159. currentCol = currentCol - 1;
  160. }
  161.  
  162. }
  163.  
  164. if (command == 'R')
  165. {
  166. if (matrix[currentRow, currentCol + 1] == 'b' || matrix[currentRow, currentCol + 1] == 'd')
  167. {
  168. matrix[currentRow, currentCol] = '.';
  169. matrix[currentRow, currentCol + 1] = 'S';
  170. currentCol = currentCol + 1;
  171. }
  172. else
  173. {
  174. matrix[currentRow, currentCol] = '.';
  175. matrix[currentRow, currentCol + 1] = 'S';
  176. currentCol = currentCol + 1;
  177. }
  178.  
  179. }
  180. }
  181.  
  182. for(int row=0;row<matrix.GetLength(0);row++)
  183. {
  184. for(int col=0;col<matrix.GetLength(1);col++)
  185. {
  186. Console.Write(matrix[row,col]);
  187. }
  188. Console.WriteLine();
  189. }
  190.  
  191. }
  192. }
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement