Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Text;
- namespace BookWorm
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- string[,] matrix = new string[n, n];
- int firstRow = 0;
- int firstCol = 0;
- int secondRow = 0;
- int secondCol = 0;
- bool dead = false;
- for (int i = 0; i < n; i++)
- {
- string input = Console.ReadLine();
- for (int j = 0; j < n; j++)
- {
- matrix[i, j] = input[j].ToString();
- if (matrix[i, j] == "f")
- {
- firstRow = i;
- firstCol = j;
- }
- else if (matrix[i, j] == "s")
- {
- secondRow = i;
- secondCol = j;
- }
- }
- }
- while (true)
- {
- string[] command = Console.ReadLine().Split().ToArray();
- if (command[0] == "up")
- {
- firstRow--;
- if (firstRow < 0)
- {
- firstRow = n - 1;
- }
- }
- else if (command[0] == "down")
- {
- firstRow++;
- if (firstRow > n - 1)
- {
- firstRow = 0;
- }
- }
- else if (command[0] == "left")
- {
- firstCol--;
- if (firstCol < 0)
- {
- firstCol = n - 1;
- }
- }
- else if (command[0] == "right")
- {
- firstCol++;
- if (firstCol > n - 1)
- {
- firstCol = 0;
- }
- }
- if (matrix[firstRow, firstCol] == "*")
- {
- matrix[firstRow, firstCol] = "f";
- }
- else if(matrix[firstRow, firstCol] == "s")
- {
- matrix[firstRow, firstCol] = "x";
- dead = true;
- }
- if (dead)
- {
- break;
- }
- if (command[1] == "up")
- {
- secondRow--;
- if (secondRow < 0)
- {
- secondRow = n - 1;
- }
- }
- else if (command[1] == "down")
- {
- secondRow++;
- if (secondRow > n - 1)
- {
- secondRow = 0;
- }
- }
- else if (command[1] == "left")
- {
- secondCol--;
- if (secondCol < 0)
- {
- secondCol = n - 1;
- }
- }
- else if (command[1] == "right")
- {
- secondCol++;
- if (secondCol > n - 1)
- {
- secondCol = 0;
- }
- }
- if (matrix[secondRow, secondCol] == "*")
- {
- matrix[secondRow, secondCol] = "s";
- }
- else if(matrix[secondRow, secondCol] == "f")
- {
- matrix[secondRow, secondCol] = "x";
- dead = true;
- }
- if (dead)
- {
- break;
- }
- }
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- Console.Write(matrix[i,j]);
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement