Advertisement
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)
- {
- var chest = Console.ReadLine().Split('|').ToList();
- string command;
- while ((command = Console.ReadLine()) != "Yohoho!")
- {
- var tokens = command.Split(' ').ToList();
- command = tokens[0];
- if (command == "Loot")
- {
- for (int i = 1; i < tokens.Count; i++)
- {
- if (!chest.Contains(tokens[i]))
- {
- chest.Insert(0, tokens[i]);
- }
- }
- }
- else if (command == "Drop")
- {
- int index = int.Parse(tokens[1]);
- if (index >= 0 && index < chest.Count)
- {
- chest.Add(chest[index]);
- chest.RemoveAt(index);
- }
- }
- else if (command == "Steal")
- {
- int count = int.Parse(tokens[1]);
- if (count >= chest.Count)
- {
- count = chest.Count;
- }
- Console.WriteLine(String.Join(", ", chest.GetRange(chest.Count - count, count)));
- chest.RemoveRange(chest.Count - count, count);
- }
- }
- if (chest.Count == 0)
- {
- Console.WriteLine("Failed treasure hunt.");
- }
- else
- {
- double averageGain = (double)String.Join("", chest).Length / chest.Count;
- Console.WriteLine($"Average treasure gain: {averageGain:f2} pirate credits.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement