static void Main(string[] args) { List <Planet> planets = new List <Planet>(); string pattern = @"^[^@:!>-]*?@[^@:!>-]*?(?<name>[A-Za-z]+)[^@:!>-]*?:[^@:!>-]*?(?<population>\d+)[^@:!>-]*?![^@:!>-]*?(?<atackType>[AD])[^@:!>-]*?![^@:!>-]*?->[^@:!>-]*?(?<count>\d+)[^@:!>-]*?$"; int number = int.Parse(Console.ReadLine()); for (int i = 0; i < number; i++) { string currLine = Console.ReadLine(); currLine = EncryptMessage(currLine); Match match = Regex.Match(currLine, pattern); if (match.Success) { Planet planet = new Planet(match.Groups["name"].Value, int.Parse(match.Groups["population"].Value), match.Groups["atackType"].Value[0], int.Parse(match.Groups["count"].Value)); planets.Add(planet); } } Console.WriteLine($"Attacked planets: {Planet.PlanetCount(planets, 'A')}"); foreach (var planet in planets.Where(a => a.AtackType == 'A').OrderBy(n => n.Name)) { Console.WriteLine($"-> {planet.Name}"); } Console.WriteLine($"Destroyed planets: {Planet.PlanetCount(planets, 'D')}"); foreach (var planet in planets.Where(a => a.AtackType == 'D').OrderBy(n => n.Name)) { Console.WriteLine($"-> {planet.Name}"); } }
static void Main() { List <Planet> planets = new List <Planet>(); const string pattern = @"@(?<planetName>[A-Za-z]+)[^@:!>-]*:(?<population>\d+)[^@:!>-]*!(?<attackType>[AD])[^@:!>-]*![^@:!>-]*->(?<soldiers>\d+)"; int numberOfCommands = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfCommands; i++) { string input = MessageDecoder(Console.ReadLine()); Match match = Regex.Match(input, pattern); if (match.Success) { planets.Add(new Planet(match.Groups["planetName"].Value, char.Parse(match.Groups["attackType"].Value))); } } Console.WriteLine($"Attacked planets: {Planet.PlanetCount(planets, 'A')}"); foreach (Planet planet in planets.Where(typeOf => typeOf.AttackType == 'A').OrderBy(planet => planet.PlanetName)) { Console.WriteLine($"-> {planet.PlanetName}"); } Console.WriteLine($"Destroyed planets: {Planet.PlanetCount(planets, 'D')}"); foreach (Planet planet in planets.Where(typeOf => typeOf.AttackType == 'D').OrderBy(planet => planet.PlanetName)) { Console.WriteLine($"-> {planet.PlanetName}"); } }