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.Threading.Tasks;
- using System.Text.RegularExpressions;
- namespace _04.Star_Enigma
- {
- class Program
- {
- static void Main(string[] args)
- {
- int numPlanetsAttacked = 0;
- int numPlanetsDestroyed = 0;
- List<string> listPlanetsAttacked = new List<string>();
- List<string> listPlanetsDestroyed = new List<string>();
- int num = int.Parse(Console.ReadLine());
- for (int i = 0; i < num; i++)
- {
- string input = Console.ReadLine();
- string inputDecrypted = string.Empty;
- string toAdd = string.Empty;
- string patternSTAR = @"[STARstar]";
- MatchCollection collectionOfKeys = Regex.Matches(input, patternSTAR);
- for (int j = 0; j < input.Length; j++)
- {
- inputDecrypted += (char)((int)input[j] - collectionOfKeys.Count);
- }
- string patternALL = @"(@([A-Za-z]+)([^@\-!:>]))(\:\d+)(![A|D]!)(->\d+)";
- Regex regexALL = new Regex(patternALL);
- bool isMatch = regexALL.IsMatch(inputDecrypted);
- if (isMatch)
- {
- Match match = regexALL.Match(inputDecrypted);
- string str = match.Groups[3].Value;
- char chr = str[0];
- if (match.Groups[5].ToString() == "!A!")
- {
- if ((int)chr >= 97 && (int)chr <= 122)
- {
- toAdd = match.Groups[2].ToString() + match.Groups[3].ToString();
- }
- else
- {
- toAdd = match.Groups[2].ToString();
- }
- numPlanetsAttacked++;
- listPlanetsAttacked.Add(toAdd);
- }
- else if (match.Groups[5].ToString() == "!D!")
- {
- if ((int)chr >= 97 && (int)chr <= 122)
- {
- toAdd = match.Groups[2].ToString() + match.Groups[3].ToString();
- }
- else
- {
- toAdd = match.Groups[2].ToString();
- }
- numPlanetsDestroyed++;
- listPlanetsDestroyed.Add(toAdd);
- }
- }
- }
- listPlanetsAttacked.Sort();
- listPlanetsDestroyed.Sort();
- Console.WriteLine($"Attacked planets: {numPlanetsAttacked}");
- foreach (var item in listPlanetsAttacked)
- {
- Console.WriteLine($"-> {item}");
- }
- Console.WriteLine($"Destroyed planets: {numPlanetsDestroyed}");
- foreach (var itemz in listPlanetsDestroyed)
- {
- Console.WriteLine($"-> {itemz}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement