Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Collections.Generic;
- namespace StarEnigma
- {
- class Program
- {
- static void Main(string[] args)
- {
- Regex pattern = new Regex(@"@(?<name>[A-Za-z]+)[^@\-!:>]*:(?<population>\d+)[^@\-!:>]*!(?<type>A|D)![^@\-!:>]*->(?<soldiers>\d+)");
- var attackedPlanets = new List<string>();
- var destroyedPlanets = new List<string>();
- int countPlanets = int.Parse(Console.ReadLine());
- for (int i = 0; i < countPlanets; i++)
- {
- string message = Console.ReadLine();
- int starLen = new Regex(@"[STARstar]")
- .Matches(message)
- .Select(x => x.Value)
- .Count();
- var decodedMessage = new StringBuilder();
- for (int j = 0; j < message.Length; j++)
- {
- decodedMessage.Append((char)(message[j] - starLen));
- }
- if (pattern.IsMatch(decodedMessage.ToString()))
- {
- var planet = pattern.Match(decodedMessage.ToString());
- if (planet.Groups["type"].Value == "A")
- {
- attackedPlanets.Add(planet.Groups["name"].Value);
- }
- else
- {
- destroyedPlanets.Add(planet.Groups["name"].Value);
- }
- }
- }
- Console.WriteLine($"Attacked planets: {(attackedPlanets.Count() > 0 ? attackedPlanets.Count() : 0)}");
- attackedPlanets.Sort();
- foreach (var planetName in attackedPlanets)
- {
- Console.WriteLine($"-> {planetName}");
- }
- Console.WriteLine($"Destroyed planets: {(destroyedPlanets.Count() > 0 ? destroyedPlanets.Count() : 0)}");
- destroyedPlanets.Sort();
- foreach (var planetName in destroyedPlanets)
- {
- Console.WriteLine($"-> {planetName}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement