Advertisement
petarkobakov

P!rates

Aug 3rd, 2020
800
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.ExceptionServices;
  5. using System.Security.Cryptography.X509Certificates;
  6.  
  7. namespace P_rates
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Dictionary<string, List <int>> populationGold = new Dictionary<string, List<int>>();
  14.  
  15.  
  16. while (true)
  17. {
  18. string sailCommand = Console.ReadLine();
  19.  
  20. if (sailCommand == "Sail")
  21. {
  22. break;
  23. }
  24. string[] populationAndGold = sailCommand.Split("||");
  25. string city = populationAndGold[0];
  26. int people = int.Parse(populationAndGold[1]);
  27. int gold = int.Parse(populationAndGold[2]);
  28.  
  29.  
  30. if (!populationGold.ContainsKey(city))
  31. {
  32. populationGold.Add(city, new List<int> { people, gold });
  33. }
  34.  
  35. else
  36. {
  37. populationGold[city][0] += people;
  38. populationGold[city][1] += gold;
  39. }
  40. }
  41.  
  42.  
  43. while (true)
  44. {
  45. string endCommand = Console.ReadLine();
  46.  
  47. if (endCommand == "End")
  48. {
  49. break;
  50. }
  51.  
  52. string[] currentEvent = endCommand.Split("=>");
  53. string operation = currentEvent[0];
  54.  
  55.  
  56. if (operation == "Plunder")
  57. {
  58. string city = currentEvent[1];
  59. int people = int.Parse(currentEvent[2]);
  60. int gold = int.Parse(currentEvent[3]);
  61.  
  62. populationGold[city][0]-= people;
  63. populationGold[city][1] -= gold;
  64.  
  65. Console.WriteLine($"{city} plundered! {gold} gold stolen, {people} citizens killed.");
  66. if (populationGold[city][0] <=0 || populationGold[city][1] <= 0)
  67. {
  68. Console.WriteLine($"{city} has been wiped off the map!");
  69. populationGold.Remove(city);
  70. }
  71.  
  72. }
  73.  
  74. else if (operation == "Prosper")
  75. {
  76. string city = currentEvent[1];
  77. int gold = int.Parse(currentEvent[2]);
  78.  
  79. if (gold<0)
  80. {
  81. Console.WriteLine($"Gold added cannot be a negative number!");
  82. continue;
  83. }
  84.  
  85. populationGold[city][1] += gold;
  86.  
  87. Console.WriteLine($"{gold} gold added to the city treasury. {city} now has {populationGold[city][1]} gold.");
  88.  
  89. }
  90. }
  91.  
  92. if (populationGold.Count == 0)
  93. {
  94. Console.WriteLine($"Ahoy, Captain! All targets have been plundered and destroyed!");
  95.  
  96. return;
  97. }
  98.  
  99. Console.WriteLine($"Ahoy, Captain! There are {populationGold.Count} wealthy settlements to go to: ");
  100.  
  101. foreach (var kvp in populationGold.OrderByDescending(x => x.Value[1]).ThenBy(x => x.Key))
  102. {
  103. Console.WriteLine($"{kvp.Key} -> Population: {kvp.Value[0]} citizens, Gold: {kvp.Value[1]} kg");
  104. }
  105. }
  106. }
  107. }
  108.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement