Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Text.RegularExpressions;
- namespace Orders
- {
- class Program
- {
- static void Main(string[] args)
- {
- int countMessages = int.Parse(Console.ReadLine());
- string firstPattern = @"[starSTAR]";
- List<string> attackPlanets = new List<string>();
- List<string> destroiedPlanets = new List<string>();
- for (int i = 0; i < countMessages; i++)
- {
- string messages = Console.ReadLine();
- MatchCollection letterMatches = Regex.Matches(messages, firstPattern);
- int countOfLetters = letterMatches.Count;
- string newMessage = string.Empty;
- foreach (var letter in messages)
- {
- newMessage += (char)(letter - countOfLetters);
- }
- string planetPattern = @"@(?<name>[A-Za-z]+)[^@\-!:>]*:(?<population>[0-9]+)[^@\-!:>]*!(?<type>A|D*)![^@\-!:>]*->(?<soldier>[0-9])+";
- Match planetArgs = Regex.Match(newMessage, planetPattern);
- if (planetArgs.Success)
- {
- string planetName = planetArgs.Groups["name"].Value;
- string type = planetArgs.Groups["type"].Value;
- if (type == "A")
- {
- attackPlanets.Add(planetName);
- }
- else if (type == "D")
- {
- destroiedPlanets.Add(planetName);
- }
- }
- }
- Console.WriteLine($"Attacked planets: {attackPlanets.Count}");
- foreach (var attackPl in attackPlanets.OrderBy(x => x))
- {
- Console.WriteLine($"-> {attackPl}");
- }
- Console.WriteLine($"Destroyed planets: {destroiedPlanets.Count}");
- foreach (var destoyedPl in destroiedPlanets.OrderBy(x => x))
- {
- Console.WriteLine($"-> {destoyedPl}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement