Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _02._Helen_s_Abduction
- {
- class Program
- {
- static int parisRow;
- static int parisCol;
- static void Main(string[] args)
- {
- int energy = int.Parse(Console.ReadLine());
- int rows = int.Parse(Console.ReadLine());
- char[][] matrix = new char[rows][];
- for (int row = 0; row < rows; row++)
- {
- char[] input = Console.ReadLine().ToCharArray();
- matrix[row] = new char[input.Length];
- for (int col = 0; col < matrix.Length; col++)
- {
- matrix[row][col] = input[col];
- char symbol = matrix[row][col];
- if (symbol == 'P')
- {
- parisRow = row;
- parisCol = col;
- matrix[row][col] = '-';
- }
- }
- }
- bool found = false;
- while (energy > 0)
- {
- string[] command = Console.ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries);
- string direction = command[0];
- int row = int.Parse(command[1]);
- int col = int.Parse(command[2]);
- ChangeOfPosition(matrix, row, col, direction);
- energy--;
- char symbolOnNextStep = matrix[parisRow][parisCol];
- if (symbolOnNextStep == 'S')
- {
- energy -= 2;
- matrix[parisRow][parisCol] = 'P';
- }
- else if (symbolOnNextStep == 'H')
- {
- matrix[parisRow][parisCol] = '-';
- found = true;
- break;
- }
- else if (symbolOnNextStep == '-')
- {
- matrix[parisRow][parisCol] = 'P';
- }
- if (energy <= 0)
- {
- matrix[parisRow][parisCol] = 'X';
- break;
- }
- }
- if (found)
- {
- Console.WriteLine($"Paris has successfully abducted Helen! Energy left: {energy}");
- }
- else
- {
- Console.WriteLine($"Paris died at {parisRow};{parisCol}.");
- }
- foreach (var row in matrix)
- {
- Console.WriteLine(string.Join("", row));
- }
- }
- private static void ChangeOfPosition(char[][] matrix, int row, int col, string direction)
- {
- matrix[row][col] = 'S';
- matrix[parisRow][parisCol] = '-';
- if (direction == "up" )
- {
- if (parisRow - 1 >= 0)
- {
- parisRow--;
- }
- }
- else if (direction == "down" )
- {
- if (parisRow + 1 < matrix.Length)
- {
- parisRow++;
- }
- }
- else if (direction =="left" )
- {
- if (parisCol - 1 >= 0)
- {
- parisCol--;
- }
- }
- else if (direction == "right" )
- {
- if (parisCol + 1 < matrix[parisRow].Length)
- {
- parisCol++;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement