Advertisement
silvana1303

p!rates

Jul 27th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using System.Text;
  5. using System.Linq;
  6.  
  7. namespace _01._Furniture
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var input = Console.ReadLine().Split("||").ToArray();
  14.  
  15.             var townPopulation = new Dictionary<string, int>();
  16.             var townGold = new Dictionary<string, int>();
  17.  
  18.             while (input[0] != "Sail")
  19.             {
  20.                 if (townPopulation.ContainsKey(input[0]))
  21.                 {
  22.                     townPopulation[input[0]] += int.Parse(input[1]);
  23.                 }
  24.                 else
  25.                 {
  26.                     townPopulation[input[0]] = int.Parse(input[1]);
  27.                 }
  28.  
  29.                 if (townGold.ContainsKey(input[0]))
  30.                 {
  31.                     townGold[input[0]] += int.Parse(input[2]);
  32.                 }
  33.                 else
  34.                 {
  35.                     townGold[input[0]] = int.Parse(input[2]);
  36.                 }
  37.  
  38.                 input = Console.ReadLine().Split("||").ToArray();
  39.             }
  40.  
  41.             var command = Console.ReadLine().Split("=>").ToArray();
  42.  
  43.             while (command[0] != "End")
  44.             {
  45.                 if (command[0] == "Plunder")
  46.                 {
  47.                     townPopulation[command[1]] -= int.Parse(command[2]);
  48.                     townGold[command[1]] -= int.Parse(command[3]);
  49.  
  50.                     Console.WriteLine($"{command[1]} plundered! {command[3]} gold stolen, {command[2]} citizens killed.");
  51.  
  52.                     if (townGold[command[1]] <= 0 || townPopulation[command[1]] <= 0)
  53.                     {
  54.                         townPopulation.Remove(command[1]);
  55.                         townGold.Remove(command[1]);
  56.                         Console.WriteLine($"{command[1]} has been wiped off the map!");
  57.                     }
  58.                    
  59.                 }
  60.                 if (command[0] == "Prosper")
  61.                 {
  62.                     int gold = int.Parse(command[2]);
  63.  
  64.                     if (gold < 0)
  65.                     {
  66.                         Console.WriteLine("Gold added cannot be a negative number!");
  67.                     }
  68.                     else
  69.                     {
  70.                         townGold[command[1]] += gold;
  71.                         int current = townGold[command[1]];
  72.                         Console.WriteLine($"{gold} gold added to the city treasury. {command[1]} now has {current} gold.");
  73.                     }
  74.                 }
  75.  
  76.                 command = Console.ReadLine().Split("=>").ToArray();
  77.             }
  78.  
  79.             if (townGold.Values.Count == 0)
  80.             {
  81.                 Console.WriteLine("Ahoy, Captain! All targets have been plundered and destroyed!");
  82.             }
  83.             else
  84.             {
  85.                 Console.WriteLine($"Ahoy, Captain! There are {townGold.Values.Count} wealthy settlements to go to:");
  86.                 Console.WriteLine(string.Join($"{Environment.NewLine}", townGold
  87.                     .OrderByDescending(x => x.Value)
  88.                     .ThenBy(x => x.Key)
  89.                     .Select(x => $"{x.Key} -> Population: {townPopulation[x.Key]} citizens, Gold: {x.Value} kg")));
  90.             }
  91.  
  92.            
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement