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 Problem03
- {
- class Program
- {
- static void Main(string[] args)
- {
- var planetCount = int.Parse(Console.ReadLine());
- var allPlanets = new List<string>();
- for (int i = 0; i < planetCount; i++)
- {
- var input = Console.ReadLine();
- var decypherCount = input.ToLower()
- .Count(p => p.Equals('s') || p.Equals('t') || p.Equals('a') || p.Equals('r'));
- var decypheredText = new StringBuilder();
- foreach (var element in input)
- {
- decypheredText.Append((char)(element - decypherCount));
- }
- allPlanets.Add(decypheredText.ToString());
- }
- ;
- var attackerRegex = @"@([a-zA-Z]+)[^@\-!:>]*:(\d+)[^@\-!:>]*\!A\![^@\-!:>]*\-\>(\d+)";
- var defenderRegex = @"@([a-zA-Z]+)[^@\-!:>]*:(\d+)[^@\-!:>]*\!D\![^@\-!:>]*\-\>(\d+)";
- var atacked = new List<string>();
- var destroyed = new List<string>();
- foreach (var planet in allPlanets)
- {
- var mathcer = Regex.Match(planet, attackerRegex);
- if (mathcer.Success)
- {
- atacked.Add(mathcer.Groups[1].Value);
- continue;
- }
- mathcer = Regex.Match(planet, defenderRegex);
- if (mathcer.Success)
- {
- destroyed.Add(mathcer.Groups[1].Value);
- }
- }
- Console.WriteLine($"Attacked planets: {atacked.Count}");
- atacked.OrderBy(p=>p).ToList().ForEach(p => Console.WriteLine($"-> {p}"));
- Console.WriteLine($"Destroyed planets: {destroyed.Count}");
- destroyed.OrderBy(p=>p).ToList().ForEach(p => Console.WriteLine($"-> {p}"));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement