Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace StarEnigma_03_18
- {
- class Program
- {
- static void Main(string[] args)
- {
- int numberOfMessages = int.Parse(Console.ReadLine());
- List<string> attackedPlanets = new List<string>();
- List<string> destroyedPlanets = new List<string>();
- for (int currentMessage = 1; currentMessage <= numberOfMessages; currentMessage++)
- {
- string message = Console.ReadLine();
- string temp = message.ToLower();
- int count = 0;
- for (int index = 0; index < temp.Length; index++)
- {
- char symbol = temp[index];
- if (symbol == 's' || symbol == 't' || symbol == 'a' || symbol == 'r')
- {
- count++;
- }
- }
- string decoded = string.Empty;
- for (int index = 0; index < message.Length; index++)
- {
- decoded += (char)(message[index] - count);
- }
- int indexOfVerbatim = decoded.IndexOf('@');
- int indexOfPoints = decoded.IndexOf(':');
- int indexOfExclamation = decoded.IndexOf('!');
- int indexOfBigger = decoded.IndexOf('>');
- if (indexOfVerbatim < 0 || indexOfPoints < 0 || indexOfExclamation < 0 || indexOfBigger < 0)
- {
- continue;
- }
- if (indexOfVerbatim > indexOfPoints || indexOfPoints > indexOfExclamation || indexOfExclamation + 2 > indexOfBigger)
- {
- continue;
- }
- if (Char.IsDigit(decoded[indexOfPoints + 1]) == false
- || Char.IsDigit(decoded[indexOfBigger + 1]) == false)
- {
- continue;
- }
- string planetName = null;
- for (int i = indexOfVerbatim + 1; i < indexOfPoints; i++)
- {
- char symbolOfPlanet = decoded[i];
- if ((symbolOfPlanet >= 'A' && symbolOfPlanet <= 'Z')
- || (symbolOfPlanet >= 'a' && symbolOfPlanet <= 'z'))
- {
- planetName += symbolOfPlanet;
- }
- else
- {
- break;
- }
- }
- char attackType = decoded[indexOfExclamation + 1];
- if (planetName != null && decoded[indexOfExclamation + 2] == '!')
- {
- if (attackType == 'A')
- {
- attackedPlanets.Add(planetName);
- }
- else if (attackType == 'D')
- {
- destroyedPlanets.Add(planetName);
- }
- }
- }
- attackedPlanets = attackedPlanets.OrderBy(p => p).ToList();
- destroyedPlanets = destroyedPlanets.OrderBy(p => p).ToList();
- Console.WriteLine($"Attacked planets: {attackedPlanets.Count}");
- foreach (string planet in attackedPlanets)
- {
- Console.WriteLine($"-> {planet}");
- }
- Console.WriteLine($"Destroyed planets: {destroyedPlanets.Count}");
- foreach (string planet in destroyedPlanets)
- {
- Console.WriteLine($"-> {planet}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment