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