using System; using System.Linq; namespace DeliveryBoy { public class Program { public static void Main(string[] args) { int[] dimentions = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); string[,] field = new string[dimentions[0], dimentions[1]]; int boyRow = -1; int boyCol = -1; int startRow = -1; int startCol = -1; bool hasLeft = false; for (int i = 0; i < field.GetLength(0); i++) { string newRow = Console.ReadLine(); for (int j = 0; j < field.GetLength(1); j++) { field[i, j] = newRow[j].ToString(); if (field[i,j] == "B") { boyRow = i; boyCol = j; startRow = i; startCol = j; } } } while (true) { string command = Console.ReadLine(); if (command == "left") { if (boyCol > 0) { if (field[boyRow, boyCol -1] == "*") { continue; } if (field[boyRow, boyCol] != "R") { field[boyRow, boyCol] = "."; } boyCol--; } else { if (field[boyRow, boyCol] == "-") { field[boyRow, boyCol] = "."; } hasLeft = true; Console.WriteLine("The delivery is late. Order is canceled."); break; } } if (command == "right") { if (boyCol < field.GetLength(1) - 1) { if (field[boyRow, boyCol + 1] == "*") { continue; } if (field[boyRow, boyCol] != "R") { field[boyRow, boyCol] = "."; } boyCol++; } else { if (field[boyRow, boyCol] == "-") { field[boyRow, boyCol] = "."; } hasLeft = true; Console.WriteLine("The delivery is late. Order is canceled."); break; } } if (command == "up") { if (boyRow > 0) { if (field[boyRow -1, boyCol] == "*") { continue; } if (field[boyRow, boyCol] != "R") { field[boyRow, boyCol] = "."; } boyRow--; } else { if (field[boyRow, boyCol] == "-") { field[boyRow, boyCol] = "."; } hasLeft = true; Console.WriteLine("The delivery is late. Order is canceled."); break; } } if (command == "down") { if (boyRow < field.GetLength(0) - 1) { if (field[boyRow + 1, boyCol] == "*") { continue; } if (field[boyRow, boyCol] != "R") { field[boyRow, boyCol] = "."; } boyRow++; } else { if (field[boyRow, boyCol] == "-") { field[boyRow, boyCol] = "."; } hasLeft = true; Console.WriteLine("The delivery is late. Order is canceled."); break; } } if (field[boyRow,boyCol] == "P") { Console.WriteLine("Pizza is collected. 10 minutes for delivery."); field[boyRow,boyCol] = "R"; continue; } if (field[boyRow,boyCol] == "A") { field[boyRow, boyCol] = "P"; Console.WriteLine("Pizza is delivered on time! Next order..."); break; } } if (hasLeft) { field[startRow, startCol] = " "; } else { field[startRow, startCol] = "B"; } for (int i = 0; i < field.GetLength(0); i++) { for (int j = 0; j < field.GetLength(1); j++) { Console.Write(field[i,j]); } Console.WriteLine(); } } } }