Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03._P_rates
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Dictionary<string, List<int>> cities = new Dictionary<string, List<int>>();
  12.             string command;
  13.             while ((command = Console.ReadLine()) != "Sail")
  14.             {
  15.                 string[] commands = command.Split("||");
  16.                 string city = commands[0];
  17.                 int population = int.Parse(commands[1]);
  18.                 int gold = int.Parse(commands[2]);
  19.                 if (!cities.ContainsKey(city))
  20.                 {
  21.                     cities.Add(city, new List<int>());
  22.                     cities[city].Add(population);
  23.                     cities[city].Add(gold);
  24.                 }
  25.                 else
  26.                 {
  27.                     cities[city][0] += population;
  28.                     cities[city][1] += gold;
  29.                 }
  30.             }
  31.             string action;
  32.             while ((action = Console.ReadLine()) != "End")
  33.             {
  34.                 string[] actions = action.Split("=>");
  35.                 string town = actions[1];
  36.                 if (actions[0] == "Plunder")
  37.                 {
  38.                     int people = int.Parse(actions[2]);
  39.                     int gold = int.Parse(actions[3]);
  40.                     cities[town][0] -= people;
  41.                     cities[town][1] -= gold;
  42.                     Console.WriteLine($"{town} plundered! {gold} gold stolen, {people} citizens killed.");
  43.                     if (cities[town][0] == 0 || cities[town][1] == 0)
  44.                     {
  45.                         cities.Remove(town);
  46.                         Console.WriteLine($"{town} has been wiped off the map!");
  47.                     }
  48.                 }
  49.                 else if (actions[0] == "Prosper")
  50.                 {
  51.                     int gold = int.Parse(actions[2]);
  52.                     if (gold < 0)
  53.                     {
  54.                         Console.WriteLine($"Gold added cannot be a negative number!");
  55.                     }
  56.                     else
  57.                     {
  58.                         cities[town][1] += gold;
  59.                         Console.WriteLine($"{gold} gold added to the city treasury. {town} now has {cities[town][1]} gold.");
  60.                     }
  61.                    
  62.                 }
  63.             }
  64.             if (cities.Count > 0)
  65.             {
  66.                 Console.WriteLine($"Ahoy, Captain! There are {cities.Count} wealthy settlements to go to:");
  67.                 foreach (var city in cities.OrderByDescending(g => g.Value[1]).ThenBy(n => n.Key))
  68.                 {
  69.                     Console.WriteLine($"{city.Key} -> Population: {city.Value[0]} citizens, Gold: {city.Value[1]} kg");
  70.                 }
  71.             }
  72.             else
  73.             {
  74.                 Console.WriteLine("Ahoy, Captain! All targets have been plundered and destroyed!");
  75.             }
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement