Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- namespace Star_Enigma
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- string pattern = @"@(?<planet>[A-Za-z]+)([^@\-!:>]*):(?<population>[\d]+)([^@\-!:>]*)!(?<attack>[AD])!([^@\-!:>]*)->(?<soldier>[0-9]+)";
- var regex = new Regex(pattern);
- List<char> decryptedMessage = new List<char>();
- var attackedPlanets = new List<string>();
- var destroyedPlanets = new List<string>();
- int count = 0;
- int counterAttacked = 0;
- int counterDestroyed = 0;
- for (int i = 0; i < n; i++)
- {
- string encryptedMessage = Console.ReadLine();
- for (int j = 0; j < encryptedMessage.Length; j++)
- {
- char symbol = encryptedMessage[j];
- if (symbol == 's' || symbol == 't' || symbol == 'a' || symbol == 'r' || symbol == 'S' || symbol == 'T' || symbol == 'A' || symbol == 'R')
- {
- count++;
- }
- }
- for (int j = 0; j < encryptedMessage.Length; j++)
- {
- int decrypt = encryptedMessage[j] - count;
- char decryptedSymbol = Convert.ToChar(decrypt);
- decryptedMessage.Add(decryptedSymbol);
- }
- string decrypted = string.Join("", decryptedMessage);
- var matches = regex.Matches(decrypted);
- foreach (Match match in matches)
- {
- var planet = match.Groups["planet"].Value;
- var population = match.Groups["population"].Value;
- var attack = match.Groups["attack"].Value;
- var soldier = match.Groups["soldier"].Value;
- if (attack == 'A'.ToString())
- {
- counterAttacked += 1;
- attackedPlanets.Add(planet);
- }
- else if (attack == 'D'.ToString())
- {
- counterDestroyed += 1;
- destroyedPlanets.Add(planet);
- }
- }
- count = 0;
- decryptedMessage.Clear();
- }
- Console.WriteLine($"Attacked planets: {counterAttacked}");
- foreach (var item in attackedPlanets.OrderBy(x => x))
- {
- Console.WriteLine($"-> {item}");
- }
- Console.WriteLine($"Destroyed planets: {counterDestroyed}");
- foreach (var item in destroyedPlanets.OrderBy(x => x))
- {
- Console.WriteLine($"-> {item}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement