Advertisement
Guest User

Untitled

a guest
Jun 21st, 2019
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _02._Helen_s_Abduction
  5. {
  6. class Program
  7. {
  8. static int parisRow;
  9. static int parisCol;
  10.  
  11. static void Main(string[] args)
  12. {
  13. int energy = int.Parse(Console.ReadLine());
  14. int rows = int.Parse(Console.ReadLine());
  15.  
  16. char[][] matrix = new char[rows][];
  17. for (int row = 0; row < rows; row++)
  18. {
  19. char[] input = Console.ReadLine().ToCharArray();
  20.  
  21. matrix[row] = new char[input.Length];
  22.  
  23. for (int col = 0; col < matrix.Length; col++)
  24. {
  25.  
  26. matrix[row][col] = input[col];
  27.  
  28. char symbol = matrix[row][col];
  29.  
  30.  
  31. if (symbol == 'P')
  32. {
  33. parisRow = row;
  34. parisCol = col;
  35. matrix[row][col] = '-';
  36. }
  37. }
  38. }
  39. bool found = false;
  40.  
  41. while (energy > 0)
  42. {
  43. string[] command = Console.ReadLine()
  44. .Split(" ", StringSplitOptions.RemoveEmptyEntries);
  45.  
  46. string direction = command[0];
  47.  
  48. int row = int.Parse(command[1]);
  49. int col = int.Parse(command[2]);
  50.  
  51. ChangeOfPosition(matrix, row, col, direction);
  52.  
  53. energy--;
  54.  
  55. char symbolOnNextStep = matrix[parisRow][parisCol];
  56. if (symbolOnNextStep == 'S')
  57. {
  58. energy -= 2;
  59. matrix[parisRow][parisCol] = 'P';
  60. }
  61.  
  62. else if (symbolOnNextStep == 'H')
  63. {
  64. matrix[parisRow][parisCol] = '-';
  65. found = true;
  66. break;
  67. }
  68. else if (symbolOnNextStep == '-')
  69. {
  70. matrix[parisRow][parisCol] = 'P';
  71. }
  72. if (energy <= 0)
  73. {
  74. matrix[parisRow][parisCol] = 'X';
  75. break;
  76. }
  77. }
  78.  
  79. if (found)
  80. {
  81. Console.WriteLine($"Paris has successfully abducted Helen! Energy left: {energy}");
  82. }
  83. else
  84. {
  85. Console.WriteLine($"Paris died at {parisRow};{parisCol}.");
  86. }
  87.  
  88. foreach (var row in matrix)
  89. {
  90. Console.WriteLine(string.Join("", row));
  91. }
  92. }
  93.  
  94. private static void ChangeOfPosition(char[][] matrix, int row, int col, string direction)
  95. {
  96. matrix[row][col] = 'S';
  97. matrix[parisRow][parisCol] = '-';
  98.  
  99. if (direction == "up" )
  100. {
  101. if (parisRow - 1 >= 0)
  102. {
  103. parisRow--;
  104. }
  105. }
  106. else if (direction == "down" )
  107. {
  108. if (parisRow + 1 < matrix.Length)
  109. {
  110. parisRow++;
  111. }
  112. }
  113. else if (direction =="left" )
  114. {
  115. if (parisCol - 1 >= 0)
  116. {
  117. parisCol--;
  118. }
  119. }
  120. else if (direction == "right" )
  121. {
  122. if (parisCol + 1 < matrix[parisRow].Length)
  123. {
  124. parisCol++;
  125. }
  126. }
  127.  
  128. }
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement