Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Threading;
- namespace ConsoleApp1
- {
- class Exam
- {
- static void Main(string[] args)
- {
- List<string> treasure = Console.ReadLine().Split('|').ToList();
- string[] command = Console.ReadLine().Split().ToArray();
- double sum = 0;
- while (command[0] != "Yohoho!")
- {
- if (command[0] == "Loot")
- {
- for (int i = 1; i < command.Length; i++)
- {
- if (!treasure.Contains(command[i]))
- {
- treasure.Insert(0, command[i]);
- }
- }
- }
- 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]);
- int lastIndex = treasure.Count - 1;
- List<string> stealed = new List<string>();
- if (count > treasure.Count)
- {
- count = treasure.Count;
- }
- for (int i = 0; i < count; i++)
- {
- stealed.Add(treasure[treasure.Count - 1]);
- treasure.Remove(treasure[treasure.Count - 1]);
- }
- stealed.Reverse();
- Console.WriteLine(string.Join(", ", stealed));
- }
- command = Console.ReadLine().Split().ToArray();
- }
- if (treasure.Count == 0)
- {
- Console.WriteLine("Failed treasure hunt.");
- }
- else
- {
- for (int i = 0; i < treasure.Count; i++)
- {
- string word = treasure[i];
- int lenght = word.Length;
- sum += lenght;
- }
- double average = sum / treasure.Count * 1.0;
- Console.WriteLine($"Average treasure gain: {average:F2} pirate credits.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement