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