Problem 02. Book Worm C# Advanced Exam - 26 October 2019
Здравейте, може ли някой да ми помогне , с тази задача. 1-вия тест минава втория гърми , заради това условие :
If he tries to move outside of the field, he is punished - he loses the last letter in the string, if there are any, and the player’s position is not changed.* Не съм използвала нито стек нито опашка и реално не знам как да премахна просто буквата ако излиза извън матрицата. пробвах всякакви начини да замеnя буквата с '-', но не става. Ще съм благодарна ако някой ми помогне за решението или ми даде поне някаква насока, как да процедирам. Благодаря предварително!
https://judge.softuni.bg/Contests/1853/CSharp-Advanced-Exam-26-October-2019
using System;
using System.Linq;
using System.Collections.Concurrent;
using System.Text;
namespace Book_Worm
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int size = int.Parse(Console.ReadLine());
char[,] matrix = new char[size, size];
            int playerRow = 0;
            int playerCol = 0;
            for (int row = 0; row < size; row++)
            {
                char[] array = Console.ReadLine()
                      .ToCharArray(); // SO---
                for (int col = 0; col < size; col++)
                {
                    char ch = array[col];
                    if (ch == 'P')
                    {
                        playerRow = row; // na koq kolona i koi red sme namerili igracha
                        playerCol = col;
                    }
                    matrix[row, col] = ch; // na tozi red i tozi red i sloji tozi element                 
                }
            }
            matrix[playerRow, playerCol] = '-';
string directions = Console.ReadLine();
bool isEnd = false;
            while (true)
            {
                while (directions != "end")
                {
                    // right -> row stay same 0, col +1; // (0, 1)
                    // left -> row stay same 0, col -1; // (0, -1)
                    // up -> row -1, col stay same 0   // (-1, 0)
                    // down -> row +1, col stay same 0 //  (1, 0)
                    switch (directions)
                    {
                        case "left":
                            playerCol -= 1;
                            matrix[playerRow, playerCol + 1] = '-';
                            break;
                        case "right":
                            playerCol += 1;
                            matrix[playerRow, playerCol - 1] = '-';
                            break;
                        case "up":
                            playerRow -= 1;
                            matrix[playerRow - 1, playerCol] = '-';
                            break;
                        case "down":
                            playerRow += 1;
                            matrix[playerRow + 1, playerCol] = '-';
                            break;
                    }
char element = matrix[playerRow, playerCol];
                    if (char.IsLetter(element))
                    {
                        input += element;
                        matrix[playerRow, playerCol] = 'P';
                    }
                    if (IsOutside(size, playerRow, playerCol))
                    {
                        char curruntChar = matrix[playerRow, playerCol] = '-';
                    }
                    directions = Console.ReadLine();
                }
                if (isEnd == false)
                {
                    break;
                }
            }
Console.WriteLine(input);
//In the end print the matrix.
            for (int row = 0; row < size; row++)
            {
                for (int col = 0; col < size; col++)
                {
                    Console.Write(matrix[row, col]);
                }
                Console.WriteLine();
            }
        }
        private static bool IsOutside(int size, int playerRow, int playerCol)
        {
            return playerRow >= size ||
                    playerRow < 0 ||
                    playerCol >= size ||
                    playerCol < 0;
        }
    }
}