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