Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace SeashellTreasure
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- string[][] jaggerArray = new string[n][];
- int collectedShellsCount = 0;
- int stolenShellsCount = 0;
- List<string> collectedShells = new List<string>();
- for (int i = 0; i < n; i++)
- {
- string[] line = Console.ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- jaggerArray[i] = new string[line.Length];
- for (int j = 0; j < line.Length; j++)
- {
- jaggerArray[i][j] = line[j];
- }
- }
- string command = Console.ReadLine();
- while (command != "Sunset")
- {
- string[] commandInfo = command.Split();
- string toDo = commandInfo[0];
- int row = int.Parse(commandInfo[1]);
- int col = int.Parse(commandInfo[2]);
- bool coordinatesExist = row >= 0 && row <= jaggerArray.Length - 1 && col >= 0 && col <= jaggerArray[row].Length - 1;
- if (toDo == "Collect")
- {
- if (coordinatesExist)
- {
- if (jaggerArray[row][col] != "-")
- {
- collectedShells.Add(jaggerArray[row][col]);
- collectedShellsCount++;
- jaggerArray[row][col] = "-";
- }
- }
- }
- else if (toDo == "Steal")
- {
- string direction = commandInfo[3];
- if (coordinatesExist)
- {
- if (jaggerArray[row][col] != "-")
- {
- stolenShellsCount++;
- jaggerArray[row][col] = "-";
- }
- switch (direction)
- {
- case "up":
- for (int i = 0; i < 3; i++)
- {
- row--;
- if (coordinatesExist)
- {
- if (jaggerArray[row][col] != "-")
- {
- stolenShellsCount++;
- jaggerArray[row][col] = "-";
- }
- }
- }
- break;
- case "down":
- for (int i = 0; i < 3; i++)
- {
- row++;
- if (coordinatesExist)
- {
- if (jaggerArray[row][col] != "-")
- {
- stolenShellsCount++;
- jaggerArray[row][col] = "-";
- }
- }
- }
- break;
- case "left":
- for (int i = 0; i < 3; i++)
- {
- col--;
- if (coordinatesExist)
- {
- if (jaggerArray[row][col] != "-")
- {
- stolenShellsCount++;
- jaggerArray[row][col] = "-";
- }
- }
- }
- break;
- case "right":
- for (int i = 0; i < 3; i++)
- {
- col++;
- if (coordinatesExist)
- {
- if (jaggerArray[row][col] != "-")
- {
- stolenShellsCount++;
- jaggerArray[row][col] = "-";
- }
- }
- }
- break;
- }
- }
- }
- command = Console.ReadLine();
- }
- foreach (string[] element in jaggerArray)
- {
- Console.WriteLine(string.Join(" ", element));
- }
- Console.Write($"Collected seashells: {collectedShellsCount} -> ");
- Console.WriteLine(string.Join(", ", collectedShells));
- Console.WriteLine($"Stolen seashells: {stolenShellsCount}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement