Задача Help-A-Mole C# Advanced Exam - 18 August 2022
https://pastebin.com/FriEDWyQ
Знам, че има решение в Judge, но искам да го реша без класове. Благодаря предварително.
https://pastebin.com/FriEDWyQ
Знам, че има решение в Judge, но искам да го реша без класове. Благодаря предварително.
Should be working now, even though not tested in judge.
chúc may mắn
using System;
namespace _01.HelpMole
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            char[,] field = new char[n, n];
            int moleRow = -1;
            int moleCol = -1;
            int points = 0;
            for (int i = 0; i < n; i++)
            {
                string row = Console.ReadLine();
                for (int j = 0; j < n; j++)
                {
                    field[i, j] = row[j];
                    if (field[i, j] == 'M')
                    {
                        moleRow = i;
                        moleCol = j;
                        field[i, j] = '-';
                    }
                }
            }
            string command = Console.ReadLine();
            while (command != "End")
            {
                if (points >= 25)
                {
                    break;
                }
                switch (command)
                {
                    case "left":
                        if (moleCol - 1 < 0)
                        {
                            Console.WriteLine("Don't try to escape the playing field!");
                            command = Console.ReadLine();
                            continue;
                        }
                        moleCol--;
                        break;
                    case "right":
                        if (moleCol + 1 >= field.GetLength(1))
                        {
                            Console.WriteLine("Don't try to escape the playing field!");
                            command = Console.ReadLine();
                            continue;
                        }
                        moleCol++;
                        break;
                    case "up":
                        if (moleRow - 1 < 0)
                        {
                            Console.WriteLine("Don't try to escape the playing field!");
                            command = Console.ReadLine();
                            continue;
                        }
                        moleRow--;
                        break;
                    case "down":
                        if (moleRow + 1 >= field.GetLength(0))
                        {
                            Console.WriteLine("Don't try to escape the playing field!");
                            command = Console.ReadLine();
                            continue;
                        }
                        moleRow++;
                        break;
                    default: break;
                }
                if (field[moleRow, moleCol] == 'S')
                {
                    points -= 3;
                    field[moleRow, moleCol] = '-';
                    //bool teleportation = false;
                    for (int i = 0; i < n; i++)
                    {
                        for (int j = 0; j < n; j++)
                        {
                            if (field[i, j] == 'S')
                            {
                                //teleportation = true;
                                moleRow = i;
                                moleCol = j;
                                field[moleRow, moleCol] = '-';
                            }
                        }
                    }
                }
                else if (char.IsDigit(field[moleRow, moleCol]) && field[moleRow, moleCol] != '-')
                {
                    points += int.Parse(field[moleRow, moleCol].ToString()); // pishe che input string not in a correct format
                    field[moleRow, moleCol] = '-';
                    //field[moleRow, moleCol] = 'M';
                }
                command = Console.ReadLine();
            }
            field[moleRow, moleCol] = 'M';
            if (points < 25)
            {
                Console.WriteLine("Too bad! The Mole lost this battle!");
                Console.WriteLine($"The Mole lost the game with a total of {points} points.");
            }
            else
            {
                Console.WriteLine("Yay! The Mole survived another game!");
                Console.WriteLine($"The Mole managed to survive with a total of {points} points.");
            }
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    Console.Write(field[i, j]);
                }
                Console.WriteLine();
            }
        }
    }
}
thanks, it worked on judge!!
Thank you so much for your help.
only up online
Run 3 provides an addictive and challenging endless running experience with its gravity-defying mechanics and progressively difficult levels, making it a favorite among fans of the genre.