Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- namespace _03StarEnigma
- {
- class Program
- {
- static void Main(string[] args)
- {
- int numOfMessages = int.Parse(Console.ReadLine());
- string pattern = @"([AaSsTtRr])";
- string pattern2 = @"@(?<planet>[A-Za-z]+)[^@\-\\!:>]*:(?<population>\d+)[^@\-\\!:>]*!(?<attack>[A-Z])!->(?<soldiers>\d+)";
- List<string> attackedPlanets = new List<string>();
- List<string> destroyedPlanets = new List<string>();
- for (int i = 1; i <= numOfMessages; i++)
- {
- string planetName = "";
- string population = "";
- string attackType = "";
- string soldiers = "";
- string message = Console.ReadLine();
- var matches = Regex.Matches(message, pattern);
- int counter = 0;
- foreach (Match symbol in matches)
- {
- counter++;
- }
- string decryptedMessage = "";
- foreach (var symbol in message)
- {
- char temp = (char)(symbol - counter);
- decryptedMessage += temp;
- }
- counter = 0;
- var matches2 = Regex.Matches(decryptedMessage, pattern2);
- foreach (Match item in matches2)
- {
- planetName = item.Groups["planet"].Value;
- population = item.Groups["population"].Value;
- attackType = item.Groups["attack"].Value;
- soldiers = item.Groups["soldiers"].Value;
- }
- if (!string.IsNullOrEmpty(soldiers))
- {
- if (attackType == "A")
- {
- attackedPlanets.Add(planetName);
- }
- else
- {
- destroyedPlanets.Add(planetName);
- }
- }
- }
- attackedPlanets.Sort();
- destroyedPlanets.Sort();
- Console.WriteLine($"Attacked planets: {attackedPlanets.Count}");
- foreach (var item in attackedPlanets)
- {
- Console.WriteLine($"-> {item}");
- }
- Console.WriteLine($"Destroyed planets: {destroyedPlanets.Count}");
- foreach (var item in destroyedPlanets)
- {
- Console.WriteLine($"-> {item}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement