Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _03._P_rates
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, List<int>> cities = new Dictionary<string, List<int>>();
- string command;
- while ((command = Console.ReadLine()) != "Sail")
- {
- string[] commands = command.Split("||");
- string city = commands[0];
- int population = int.Parse(commands[1]);
- int gold = int.Parse(commands[2]);
- if (!cities.ContainsKey(city))
- {
- cities.Add(city, new List<int>());
- cities[city].Add(population);
- cities[city].Add(gold);
- }
- else
- {
- cities[city][0] += population;
- cities[city][1] += gold;
- }
- }
- string action;
- while ((action = Console.ReadLine()) != "End")
- {
- string[] actions = action.Split("=>");
- string town = actions[1];
- if (actions[0] == "Plunder")
- {
- int people = int.Parse(actions[2]);
- int gold = int.Parse(actions[3]);
- cities[town][0] -= people;
- cities[town][1] -= gold;
- Console.WriteLine($"{town} plundered! {gold} gold stolen, {people} citizens killed.");
- if (cities[town][0] == 0 || cities[town][1] == 0)
- {
- cities.Remove(town);
- Console.WriteLine($"{town} has been wiped off the map!");
- }
- }
- else if (actions[0] == "Prosper")
- {
- int gold = int.Parse(actions[2]);
- if (gold < 0)
- {
- Console.WriteLine($"Gold added cannot be a negative number!");
- }
- else
- {
- cities[town][1] += gold;
- Console.WriteLine($"{gold} gold added to the city treasury. {town} now has {cities[town][1]} gold.");
- }
- }
- }
- if (cities.Count > 0)
- {
- Console.WriteLine($"Ahoy, Captain! There are {cities.Count} wealthy settlements to go to:");
- foreach (var city in cities.OrderByDescending(g => g.Value[1]).ThenBy(n => n.Key))
- {
- Console.WriteLine($"{city.Key} -> Population: {city.Value[0]} citizens, Gold: {city.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