Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace CSharp_Advanced_Exercise
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- char[][] matrix = new char[n][];
- int firstRow = 0;
- int firstCol = 0;
- int secondRow = 0;
- int secondCol = 0;
- for (int i = 0; i < n; i++)
- {
- char[] input = Console.ReadLine().ToCharArray();
- matrix[i] = input;
- if(matrix[i].Contains('f'))
- {
- int index = Array.IndexOf(matrix[i], 'f');
- firstRow = i;
- firstCol = index;
- }
- if (matrix[i].Contains('s'))
- {
- int index = Array.IndexOf(matrix[i], 's');
- secondRow = i;
- secondCol = index;
- }
- }
- while(true)
- {
- string[] input = Console.ReadLine().Split();
- string firstMove = input[0];
- string secondMove = input[1];
- switch(firstMove)
- {
- case "down":
- {
- firstRow++;
- if(firstRow == matrix.Length)
- {
- firstRow = 0;
- }
- if(matrix[firstRow][firstCol] == 's')
- {
- matrix[firstRow][firstCol] = 'x';
- break;
- }
- matrix[firstRow][firstCol] = 'f';
- break;
- }
- case "up":
- {
- firstRow--;
- if (firstRow < 0)
- {
- firstRow = matrix.Length - 1;
- }
- if (matrix[firstRow][firstCol] == 's')
- {
- matrix[firstRow][firstCol] = 'x';
- break;
- }
- matrix[firstRow][firstCol] = 'f';
- break;
- }
- case "left":
- {
- firstCol--;
- if (firstCol < 0)
- {
- firstCol = matrix.Length - 1;
- }
- if (matrix[firstRow][firstCol] == 's')
- {
- matrix[firstRow][firstCol] = 'x';
- break;
- }
- matrix[firstRow][firstCol] = 'f';
- break;
- }
- case "right":
- {
- firstCol++;
- if (firstCol == matrix.Length)
- {
- firstCol = 0;
- }
- if (matrix[firstRow][firstCol] == 's')
- {
- matrix[firstRow][firstCol] = 'x';
- break;
- }
- matrix[firstRow][firstCol] = 'f';
- break;
- }
- }
- foreach (char[] row in matrix)
- {
- if (row.Contains('x'))
- {
- foreach (char[] rowToPrint in matrix)
- {
- Console.WriteLine(rowToPrint);
- }
- return;
- }
- }
- switch (secondMove)
- {
- case "down":
- {
- secondRow++;
- if(secondRow == matrix.Length)
- {
- secondRow = 0;
- }
- if(matrix[secondRow][secondCol] == 'f')
- {
- matrix[secondRow][secondCol] = 'x';
- break;
- }
- matrix[secondRow][secondCol] = 's';
- break;
- }
- case "up":
- {
- secondRow--;
- if (secondRow < 0)
- {
- secondRow = matrix.Length - 1;
- }
- if (matrix[secondRow][secondCol] == 'f')
- {
- matrix[secondRow][secondCol] = 'x';
- break;
- }
- matrix[secondRow][secondCol] = 's';
- break;
- }
- case "left":
- {
- secondCol--;
- if (secondCol < 0)
- {
- secondCol = matrix.Length - 1;
- }
- if (matrix[secondRow][secondCol] == 'f')
- {
- matrix[secondRow][secondCol] = 'x';
- break;
- }
- matrix[secondRow][secondCol] = 's';
- break;
- }
- case "right":
- {
- secondCol++;
- if (secondCol == matrix.Length)
- {
- secondCol = 0;
- }
- if (matrix[secondRow][secondCol] == 'f')
- {
- matrix[secondRow][secondCol] = 'x';
- break;
- }
- matrix[secondRow][secondCol] = 's';
- break;
- }
- }
- foreach(char[] row in matrix)
- {
- if (row.Contains('x'))
- {
- foreach(char[] rowToPrint in matrix)
- {
- Console.WriteLine(rowToPrint);
- }
- return;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement