Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace TreasureHunt
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> treasureChest = Console.ReadLine()
- .Split("|")
- .ToList();
- string command;
- while ((command = Console.ReadLine()) != "Yohoho!")
- {
- string[] commandArgs = command.Split(' ').ToArray();
- string commandType = commandArgs[0];
- if (commandType == "Loot")
- {
- for (int i = 1; i < commandArgs.Length; i++)
- {
- string itemToInsert = commandArgs[i];
- if (treasureChest.Contains(itemToInsert))
- {
- continue;
- }
- else
- {
- treasureChest.Insert(0, itemToInsert);
- }
- }
- }
- if (commandType == "Drop")
- {
- int index = int.Parse(commandArgs[1]);
- if (index < 0 || index >= treasureChest.Count)
- {
- continue;
- }
- else
- {
- string temp = treasureChest[index];
- treasureChest.RemoveAt(index);
- treasureChest.Add(temp);
- }
- }
- if (commandType == "Steal")
- {
- int count = int.Parse(commandArgs[1]);
- if (count > treasureChest.Count)
- {
- count = treasureChest.Count;
- List<string> stolenLoot = new List<string>();
- for (int i = 0; i < count; i++)
- {
- stolenLoot.Add(treasureChest[treasureChest.Count - 1]);
- treasureChest.Remove(treasureChest[treasureChest.Count - 1]);
- }
- stolenLoot.Reverse();
- Console.WriteLine(string.Join(", ", stolenLoot));
- }
- else
- {
- List<string> stolenLoot = new List<string>();
- for (int i = 0; i < count; i++)
- {
- stolenLoot.Add(treasureChest[treasureChest.Count - 1]);
- treasureChest.Remove(treasureChest[treasureChest.Count - 1]);
- }
- stolenLoot.Reverse();
- Console.WriteLine(string.Join(", ", stolenLoot));
- }
- }
- }
- if (treasureChest.Count == 0)
- {
- Console.WriteLine($"Failed treasure hunt.");
- }
- else
- {
- double sum = 0.0;
- for (int i = 0; i < treasureChest.Count; i++)
- {
- sum += treasureChest[i].Count();
- }
- double averageGain = sum / treasureChest.Count();
- Console.WriteLine($"Average treasure gain: {averageGain:F2} pirate credits.");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment