Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace SeashellTreasure
- {
- public class StartUp
- {
- public static void Main(string[] args)
- {
- int numOfRows = int.Parse(Console.ReadLine());
- var beach = new string[numOfRows][];
- for (int row = 0; row < numOfRows; row++)
- {
- var curRrow = Console.ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries);
- beach[row] = curRrow;
- }
- List<string> collected = new List<string>();
- int stolen = 0;
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "Sunset")
- {
- break;
- }
- var command = input
- .Split();
- if (command[0] == "Collect")
- {
- int collectRow = int.Parse(command[1]);
- int collectCol = int.Parse(command[2]);
- if (IsInRange(beach, collectRow, collectCol) && IsContaining(beach, collectRow, collectCol))
- {
- collected.Add(beach[collectRow][collectCol]);
- ReturnDash(ref beach, collectRow, collectCol);
- }
- }
- else if (command[0] == "Steal")
- {
- int stealRow = int.Parse(command[1]);
- int stealCol = int.Parse(command[2]);
- string direction = command[3];
- if (IsInRange(beach, stealRow, stealCol))
- {
- if (IsContaining(beach, stealRow, stealCol))
- {
- stolen++;
- ReturnDash(ref beach, stealRow, stealCol);
- }
- }
- else
- {
- continue;
- }
- switch (direction)
- {
- case "up":
- if (IsInRange(beach, stealRow - 3, stealCol))
- {
- for (int row = stealRow; row >= stealRow - 3; row--)
- {
- if (IsContaining(beach, row, stealCol))
- {
- stolen++;
- ReturnDash(ref beach, row, stealCol);
- }
- }
- }
- else
- {
- continue;
- }
- break;
- case "down":
- if (IsInRange(beach, stealRow + 3, stealCol))
- {
- for (int row = stealRow; row <= stealRow + 3; row++)
- {
- if (IsContaining(beach, row, stealCol))
- {
- stolen++;
- ReturnDash(ref beach, row, stealCol);
- }
- }
- }
- else
- {
- continue;
- }
- break;
- case "left":
- if (IsInRange(beach, stealRow, stealCol - 3))
- {
- for (int col = stealCol; col >= stealCol - 3; col--)
- {
- if (IsContaining(beach, stealRow, col))
- {
- stolen++;
- ReturnDash(ref beach, stealRow, col);
- }
- }
- }
- else
- {
- continue;
- }
- break;
- case "right":
- if (IsInRange(beach, stealRow, stealCol + 3))
- {
- for (int col = stealCol; col <= stealCol + 3; col++)
- {
- if (IsContaining(beach, stealRow, col))
- {
- stolen++;
- ReturnDash(ref beach, stealRow, col);
- }
- }
- }
- else
- {
- continue;
- }
- break;
- }
- }
- }
- foreach (var row in beach)
- {
- Console.WriteLine(string.Join(" ", row));
- }
- if (collected.Count > 0)
- {
- Console.Write("Collected seashells: " + collected.Count + " -> " + string.Join(", ", collected));
- Console.WriteLine();
- }
- else
- {
- Console.WriteLine("Collected seashells: " + collected.Count);
- }
- Console.WriteLine($"Stolen seashells: {stolen}");
- }
- public static bool IsContaining(string[][] arr, int row, int col)
- {
- if (arr[row][col] == "C" || arr[row][col] == "N" || arr[row][col] == "M")
- {
- return true;
- }
- return false;
- }
- public static bool IsInRange(string[][] arr, int row, int col)
- {
- if (row >= 0 && row < arr.Length && col >= 0 && col < arr[row].Length)
- {
- return true;
- }
- return false;
- }
- public static void ReturnDash(ref string[][] arr, int row, int col)
- {
- arr[row][col] = "-";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement