Advertisement
Guest User

Untitled

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