Krum_50

P!rates

Jul 22nd, 2021
1,077
355 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. class Pirates
  5.     {
  6.         static void Main()
  7.         {
  8.             Dictionary<string, int> allCitiesGold = new Dictionary<string, int>();
  9.             Dictionary<string, int> allCitiesPopulation = new Dictionary<string, int>();
  10.             string cities_gold_population = Console.ReadLine();
  11.             while (cities_gold_population != "Sail")
  12.             {
  13.                 string[] tokens = cities_gold_population.Split("||").ToArray();
  14.                 string city = tokens[0];
  15.                 int population = int.Parse(tokens[1]);
  16.                 int amountOfGold = int.Parse(tokens[2]);
  17.                 if (!allCitiesGold.ContainsKey(city))                       //Пълним двата речника//
  18.                 {
  19.                     allCitiesGold.Add(city, amountOfGold);
  20.                 }
  21.                 else
  22.                 {
  23.                     allCitiesGold[city] += amountOfGold;
  24.                 }
  25.                 if (!allCitiesPopulation.ContainsKey(city))
  26.                 {
  27.                     allCitiesPopulation.Add(city, population);
  28.                 }
  29.                 else
  30.                 {
  31.                     allCitiesPopulation[city] += population;
  32.                 }
  33.                 cities_gold_population = Console.ReadLine();
  34.                 tokens = cities_gold_population.Split("||").ToArray();
  35.             }
  36.             string action = Console.ReadLine();
  37.            while (action != "End")
  38.            {
  39.             string[] tokens = action.Split("=>").ToArray();
  40.             string command = tokens[0];
  41.             if (command == "Plunder")
  42.             {
  43.                 string town = tokens[1];
  44.                 int people = int.Parse(tokens[2]);
  45.                 int gold = int.Parse(tokens[3]);
  46.                 Console.WriteLine($"{town} plundered! {gold} gold stolen, {people} citizens killed.");
  47.                 if (allCitiesPopulation[town] - people <= 0)
  48.                 {
  49.                     allCitiesPopulation.Remove(town);
  50.                     Console.WriteLine("{town} has been wiped off the map!");
  51.                 }
  52.                 else
  53.                 {
  54.                     allCitiesPopulation[town] = allCitiesPopulation[town] - people;
  55.                     allCitiesGold[town] = allCitiesGold[town] - gold;
  56.  
  57.                 }
  58.             }
  59.             if (command == "Prosper")
  60.             {
  61.                 string town = tokens[1];
  62.                 int gold = int.Parse(tokens[2]);
  63.                 if (gold < 0)
  64.                 {
  65.                     Console.WriteLine($"Gold added cannot be a negative number!");
  66.                 }
  67.                 else
  68.                 {
  69.                     Console.WriteLine($"{gold} gold added to the city treasury. {town} now has {allCitiesGold[town] + gold} gold.");
  70.                     allCitiesGold[town] += gold;
  71.                 }
  72.  
  73.             }
  74.             action = Console.ReadLine();
  75.             tokens = action.Split("=>").ToArray();
  76.            }
  77.             Console.WriteLine($"Ahoy, Captain! There are {allCitiesGold.Keys.Count} wealthy settlements to go to:");
  78.             foreach (var name in allCitiesGold.OrderByDescending(x => x.Value).ThenBy(y => y.Key))
  79.             {
  80.                 Console.WriteLine($"{name.Key} -> Population: {allCitiesPopulation[name.Key]} citizens, Gold: {name.Value} kg");
  81.             }
  82.  
  83.         }
  84.     }
  85.  
  86.  
  87.  
  88.    
  89.  
  90.  
  91.  
  92.                                    
  93.          
RAW Paste Data