Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace StarEnigma
- {
- class Program
- {
- static void Main(string[] args)
- {
- int numberOfMessages = int.Parse(Console.ReadLine());
- string decryptingPattern = @"[sSTtaARr]";
- string pattern = @"@([A-Za-z]+)[^@\-!:>]*:([0-9]+)\!([AD])\![^@\-!:>]*->([0-9]+)";
- Regex regex = new Regex(decryptingPattern);
- Regex regexForResult = new Regex(pattern);
- int countOfMatchedSymbols = int.MinValue;
- StringBuilder sb = new StringBuilder();
- List<string> destroyedPlanets = new List<string>();
- List<string> attackedPlanets = new List<string>();
- for (int i = 0; i < numberOfMessages; i++)
- {
- string encryptedMessage = Console.ReadLine();
- string decryptedMsg = "";
- if (regex.IsMatch(encryptedMessage))
- {
- countOfMatchedSymbols = Regex.Matches(encryptedMessage, decryptingPattern).Count;
- }
- var messageCharArr = encryptedMessage.ToCharArray();
- foreach (var character in messageCharArr)
- {
- sb.Append((char)(character - countOfMatchedSymbols));
- decryptedMsg += sb;
- }
- Match match = regexForResult.Match(decryptedMsg);
- if (match.Success)
- {
- if (match.Groups[3].Value =="D")
- {
- destroyedPlanets.Add(match.Groups[1].Value);
- }
- else if (match.Groups[3].Value == "A")
- {
- attackedPlanets.Add(match.Groups[1].Value);
- }
- }
- sb.Clear();
- decryptedMsg = "";
- }
- Console.WriteLine($"Attacked planets: {attackedPlanets.Count}");
- if (attackedPlanets.Count>0)
- {
- foreach (var planet in attackedPlanets.OrderBy(x => x))
- {
- Console.WriteLine("-> "+planet);
- }
- }
- Console.WriteLine($"Destroyed planets: {destroyedPlanets.Count}");
- if (destroyedPlanets.Count>0)
- {
- foreach (var planet in destroyedPlanets.OrderBy(x => x))
- {
- Console.WriteLine("-> " + planet);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement