Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Seashell_Treasure
- {
- class Program
- {
- static char[][] beach;
- static int givenRow;
- static int givenCol;
- static int stolenShells;
- static void Main(string[] args)
- {
- int numberRows = int.Parse(Console.ReadLine());
- beach = new char[numberRows][];
- PopulateBeach();
- string input;
- var collectShells = new List<char>();
- stolenShells=0;
- while ((input=Console.ReadLine())!="Sunset")
- {
- var inputArray = input.Split();
- string command = inputArray[0];
- givenRow = int.Parse(inputArray[1]);
- givenCol = int.Parse(inputArray[2]);
- if (command=="Collect" && IsExist(givenRow, givenCol) && beach[givenRow][givenCol] != '-')
- {
- char shell = beach[givenRow][givenCol];
- collectShells.Add(shell);
- beach[givenRow][givenCol] = '-';
- }
- else if (command == "Steal")
- {
- string direction = inputArray[3];
- switch (direction)
- {
- case "up":
- MoveUp();
- break;
- case "down":
- MoveDown();
- break;
- case "left":
- MoveLeft();
- break;
- case "right":
- MoveRight();
- break;
- default:
- break;
- }
- }
- }
- PrintBeach();
- if (collectShells.Count!=0)
- {
- Console.WriteLine($"Collected seashells: {collectShells.Count} -> {string.Join(", ", collectShells)}");
- }
- else
- {
- Console.WriteLine($"Collected seashells: {collectShells.Count}");
- }
- Console.WriteLine($"Stolen seashells: {stolenShells}");
- }
- private static void MoveUp()
- {
- for (int i = givenRow; i >= givenRow - 3; i--)
- {
- if (IsExist(i, givenCol) && beach[i][givenCol] != '-')
- {
- stolenShells++;
- beach[i][givenCol] = '-';
- }
- }
- }
- private static void MoveDown()
- {
- for (int i = givenRow; i <= givenRow + 3; i++)
- {
- if (IsExist(i, givenCol) && beach[i][givenCol] != '-')
- {
- stolenShells++;
- beach[i][givenCol] = '-';
- }
- }
- }
- private static void MoveLeft()
- {
- for (int i = givenCol; i >= givenCol - 3; i--)
- {
- if (IsExist(givenRow, i) && beach[givenRow][i] != '-')
- {
- stolenShells++;
- beach[givenRow][i] = '-';
- }
- }
- }
- private static void MoveRight()
- {
- for (int i = givenCol; i <= givenCol + 3; i++)
- {
- if (IsExist(givenRow, i) && beach[givenRow][i] != '-')
- {
- stolenShells++;
- beach[givenRow][i] = '-';
- }
- }
- }
- private static bool IsExist(int row, int col)
- {
- return
- row >= 0 && row < beach.Length &&
- col >= 0 && col < beach[row].Length;
- }
- private static void PrintBeach()
- {
- foreach (var row in beach)
- {
- Console.WriteLine(string.Join(' ', row));
- }
- }
- private static void PopulateBeach()
- {
- for (int row = 0; row < beach.Length; row++)
- {
- var input = Console.ReadLine().Split(" ",StringSplitOptions.RemoveEmptyEntries).Select(char.Parse).ToArray();
- for (int col = 0; col < input.Length; col++)
- {
- beach[row] = input;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement