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