Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Treasure_Hunt
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> treasureLIst = Console.ReadLine()
- .Split('|', StringSplitOptions.RemoveEmptyEntries)
- .ToList();
- while (true)
- {
- string[] commands = Console.ReadLine()
- .Split()
- .ToArray();
- if (commands[0] == "Yohoho!")
- { break; }
- switch (commands[0])
- {
- case "Loot":
- treasureLIst = GetLootedList(treasureLIst, commands);
- break;
- case "Drop":
- int index = int.Parse(commands[1]);
- if (index < 0 || index > treasureLIst.Count - 1)
- { continue; }
- else
- {
- string current = treasureLIst[index];
- treasureLIst.RemoveAt(index);
- treasureLIst.Add(current);
- }
- break;
- case "Steal":
- int count = int.Parse(commands[1]);
- if (count <= 0)
- { continue; }
- GetStealList(treasureLIst, count);
- break;
- }
- }
- double sumofletters = 0;
- for (int i = 0; i < treasureLIst.Count; i++)
- {
- int cur = treasureLIst[i].Length;
- sumofletters += cur;
- }
- if (treasureLIst.Count > 0)
- {
- double needForPrint = sumofletters / (treasureLIst.Count);
- Console.WriteLine($"Average treasure gain: {needForPrint:f2} pirate credits.");
- }
- else
- { Console.WriteLine("Failed treasure hunt."); }
- }
- static List<string> GetStealList(List<string> treasureLIst, int count)
- {
- List<string> stealitems = new List<string>();
- for (int i = 1; i <= count; i++)
- {
- string current = treasureLIst[treasureLIst.Count - 1];
- stealitems.Add(current);
- treasureLIst.RemoveAt(treasureLIst.Count - 1);
- }
- stealitems.Reverse();
- Console.WriteLine(String.Join(", ", stealitems));
- return treasureLIst;
- }
- static List<string> GetLootedList(List<string> treasureLIst, string[] commands)
- {
- List<string> newitems = new List<string>();
- List<string> newTresure = new List<string>();
- for (int i = 1; i < commands.Length; i++)
- {
- newitems.Add(commands[i]);
- if (treasureLIst.Contains(commands[i]))
- {
- newitems.Remove(commands[i]);
- }
- }
- newitems.Reverse();
- for (int j = 0; j < newitems.Count; j++)
- {
- newTresure.Add(newitems[j]);
- }
- for (int k = 0; k < treasureLIst.Count; k++)
- {
- newTresure.Add(treasureLIst[k]);
- }
- treasureLIst = newTresure;
- return treasureLIst;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement