Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Text.RegularExpressions;
- using System.Collections.Generic;
- using System.Text;
- namespace _03._Pirates
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- SortedDictionary<string, List<int>> city = new SortedDictionary<string, List<int>>();
- while (input != "Sail")
- {
- string[] cities = input.Split("||").ToArray();
- string cityname = cities[0];
- int population = int.Parse(cities[1]);
- int gold = int.Parse(cities[2]);
- if (!city.ContainsKey(cityname))
- {
- city.Add(cityname, new List<int>(2));
- city[cityname].Add(population);
- city[cityname].Add(gold);
- }
- else
- {
- city[cityname][0] += population;
- city[cityname][1] += gold;
- }
- input = Console.ReadLine();
- }
- string events = Console.ReadLine();
- while (events != "End")
- {
- string[] command = events.Split("=>").ToArray();
- switch (command[0])
- {
- case "Plunder":
- int people = int.Parse(command[2]);
- int golds = int.Parse(command[3]);
- if (city.ContainsKey(command[1]))
- {
- city[command[1]][0] -= people;
- city[command[1]][1] -= golds;
- Console.WriteLine($"{command[1]} plundered! {golds} gold stolen, {people} citizens killed.");
- if ((city[command[1]][0] <= 0) || (city[command[1]][1] <= 0))
- {
- Console.WriteLine($"{command[1]} has been wiped off the map!");
- city.Remove(command[1]);
- }
- }
- break;
- case "Prosper":
- int goldy = int.Parse(command[2]);
- if (goldy < 0)
- {
- Console.WriteLine("Gold added cannot be a negative number!");
- break;
- }
- else
- {
- city[command[1]][1] += goldy;
- Console.WriteLine($"{goldy} gold added to the city treasury. {command[1]} now has {city[command[1]][1]} gold.");
- }
- break;
- }
- events = Console.ReadLine();
- }
- if (city.Count > 0)
- {
- Console.WriteLine($"Ahoy, Captain! There are {city.Count} wealthy settlements to go to:");
- foreach (var item in city.OrderByDescending(x => x.Value[1]))
- {
- Console.WriteLine($"{item.Key} -> Population: {item.Value[0]} citizens, Gold: {item.Value[1]} kg");
- }
- }
- else
- {
- Console.WriteLine("Ahoy, Captain! All targets have been plundered and destroyed!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement