Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Numerics;
- using System.Threading;
- using System.Transactions;
- namespace exampreparation
- {
- class exam
- {
- static void Main(string[] args)
- {
- List<string> treasure = Console.ReadLine().Split('|').ToList();
- string[] command = Console.ReadLine().Split().ToArray();
- while (command[0] != "Yohoho!")
- {
- if (command[0] == "Loot")
- {
- List<string> loot = new List<string>();
- for (int i = 1; i < command.Length; i++)
- {
- if (!treasure.Contains(command[i]))
- {
- loot.Add(command[i]);
- }
- }
- loot.Reverse();
- treasure.InsertRange(0, loot);
- }
- if (command[0] == "Drop")
- {
- int index = int.Parse(command[1]);
- if (index >= 0 && index < treasure.Count)
- {
- string temp = treasure[index];
- treasure.RemoveAt(index);
- treasure.Add(temp);
- }
- }
- if (command[0] == "Steal")
- {
- int count = int.Parse(command[1]);
- if (count > treasure.Count)
- {
- count = treasure.Count;
- }
- treasure.Reverse();
- List<string> steal = treasure.GetRange(0, count);
- treasure.RemoveRange(0, count);
- steal.Reverse();
- Console.WriteLine(string.Join(", ", steal));
- treasure.Reverse();
- }
- command = Console.ReadLine().Split().ToArray();
- }
- double sum = 0;
- for (int i = 0; i < treasure.Count; i++)
- {
- sum += treasure[i].Length;
- }
- double average = sum / treasure.Count * 1.0;
- if (treasure.Count == 0)
- {
- Console.WriteLine("Failed treasure hunt.");
- }
- else
- {
- Console.WriteLine($"Average treasure gain: {average:F2} pirate credits.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement