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