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