Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Linq;
- namespace _3._Star_Enigma
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- List<StringBuilder> decryptedMessages = new List<StringBuilder>();
- for (int i = 0; i < n; i++)
- {
- string messages = Console.ReadLine();
- string patternKey = @"[sStTaArR]";
- Regex regex = new Regex(patternKey);
- MatchCollection matches = regex.Matches(messages);
- int countDeleteAscii = matches.Count;
- StringBuilder decryptMessage = new StringBuilder();
- for (int j = 0; j < messages.Length; j++)
- {
- decryptMessage.Append(Convert.ToChar(messages[j] - countDeleteAscii));
- }
- decryptedMessages.Add(decryptMessage);
- }
- List<string> attacked = new List<string>();
- List<string> destryed = new List<string>();
- foreach (var item in decryptedMessages)
- {
- string[] splitting = item.ToString().Split(new[] {'@',':'}).ToArray();
- string name = splitting[1];
- string namePattern = @"[A-Za-z]+";
- Regex regexName = new Regex(namePattern);
- Match matchName = regexName.Match(name);
- if (!matchName.Success)
- {
- continue;
- }
- string patternPlanetPopulation = @"[0-9]+(?=!)";
- Regex regexPopulation = new Regex(patternPlanetPopulation);
- Match matchPopulation = regexPopulation.Match(splitting[2]);
- if (!matchPopulation.Success)
- {
- continue;
- }
- string patternAttack = @"![A|D]!";
- Regex regexAttack = new Regex(patternAttack);
- Match matchAttack = regexAttack.Match(splitting[2]);
- if (!matchAttack.Success)
- {
- continue;
- }
- string patternSoldierCount = @"(?<=->)[0-9]*";
- Regex regexSoldiers = new Regex(patternSoldierCount);
- Match matchSoldiers = regexSoldiers.Match(splitting[2]);
- if (!matchSoldiers.Success)
- {
- continue;
- }
- if (matchAttack.ToString() == "!A!")
- {
- attacked.Add(matchName.ToString());
- }
- if (matchAttack.ToString() == "!D!")
- {
- destryed.Add(matchName.ToString());
- }
- }
- if (attacked.Count == 0)
- {
- Console.WriteLine("Attacked planets: 0");
- }
- else
- {
- Console.WriteLine($"Attacked planets: {attacked.Count}");
- foreach (var item in attacked)
- {
- Console.WriteLine($"-> {item}");
- }
- }
- if (destryed.Count == 0)
- {
- Console.WriteLine("Destroyed planets: 0");
- }
- else
- {
- Console.WriteLine($"Destroyed planets: {destryed.Count}");
- foreach (var item in destryed.OrderBy(x=>x))
- {
- Console.WriteLine($"-> {item}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement