Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace P_rates
- {
- class Program
- {
- static void Main(string[] args)
- {
- string command = Console.ReadLine();
- Dictionary<string, List<int>> allCities = new Dictionary<string, List<int>>();
- while (command.ToLower() != "sail")
- {
- string[] citiesArray = command.Split("||", StringSplitOptions.RemoveEmptyEntries);
- string currentCity = citiesArray[0];
- int population = int.Parse(citiesArray[1]);
- int gold = int.Parse(citiesArray[2]);
- if (allCities.ContainsKey(currentCity))
- {
- allCities[currentCity][0] += population;
- allCities[currentCity][1] += gold;
- }
- else
- {
- allCities.Add(currentCity, new List<int>() { population, gold });
- }
- command = Console.ReadLine();
- }
- string continousCommands = Console.ReadLine();
- while (continousCommands.ToLower() != "end")
- {
- string[] commandsArray = continousCommands.Split("=>", StringSplitOptions.RemoveEmptyEntries);
- string commandToSwitch = commandsArray[0];
- switch (commandToSwitch)
- {
- case "Plunder":
- string town = commandsArray[1];
- int peopleToPlunder = int.Parse(commandsArray[2]);
- int goldToPlunder = int.Parse(commandsArray[3]);
- if (allCities[town][0] - peopleToPlunder > 0 && allCities[town][1] - goldToPlunder > 0)
- {
- allCities[town][0] -= peopleToPlunder;
- allCities[town][1] -= goldToPlunder;
- Console.WriteLine($"{town} plundered! {goldToPlunder} gold stolen, {peopleToPlunder} citizens killed.");
- }
- else if (allCities[town][0] - peopleToPlunder <= 0 || allCities[town][1] - goldToPlunder <= 0)
- {
- Console.WriteLine($"{town} plundered! {goldToPlunder} gold stolen, {peopleToPlunder} citizens killed.");
- allCities.Remove(town);
- Console.WriteLine($"{town} has been wiped off the map!");
- }
- break;
- case "Prosper":
- string prosperTown = commandsArray[1];
- int goldToIncrease = int.Parse(commandsArray[2]);
- if (goldToIncrease < 0)
- {
- Console.WriteLine("Gold added cannot be a negative number!");
- continousCommands = Console.ReadLine();
- continue;
- }
- else
- {
- allCities[prosperTown][1] += goldToIncrease;
- Console.WriteLine($"{goldToIncrease} gold added to the city treasury. {prosperTown} now has {allCities[prosperTown][1]} gold.");
- }
- break;
- }
- continousCommands = Console.ReadLine();
- }
- Console.WriteLine($"Ahoy, Captain! There are {allCities.Count} wealthy settlements to go to: ");
- foreach (var gold in allCities.OrderByDescending(g => g.Value[1]).ThenBy(a => a.Key))
- {
- Console.WriteLine($"{gold.Key} -> Population: {gold.Value[0]} citizens, Gold: {gold.Value[1]} kg");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement