Advertisement
Prohause

Star Enigma

Aug 1st, 2018
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace Problem03
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var planetCount = int.Parse(Console.ReadLine());
  14. var allPlanets = new List<string>();
  15. for (int i = 0; i < planetCount; i++)
  16. {
  17. var input = Console.ReadLine();
  18. var decypherCount = input.ToLower()
  19. .Count(p => p.Equals('s') || p.Equals('t') || p.Equals('a') || p.Equals('r'));
  20. var decypheredText = new StringBuilder();
  21.  
  22. foreach (var element in input)
  23. {
  24. decypheredText.Append((char)(element - decypherCount));
  25. }
  26.  
  27. allPlanets.Add(decypheredText.ToString());
  28. }
  29. ;
  30. var attackerRegex = @"@([a-zA-Z]+)[^@\-!:>]*:(\d+)[^@\-!:>]*\!A\![^@\-!:>]*\-\>(\d+)";
  31. var defenderRegex = @"@([a-zA-Z]+)[^@\-!:>]*:(\d+)[^@\-!:>]*\!D\![^@\-!:>]*\-\>(\d+)";
  32.  
  33. var atacked = new List<string>();
  34. var destroyed = new List<string>();
  35.  
  36. foreach (var planet in allPlanets)
  37. {
  38. var mathcer = Regex.Match(planet, attackerRegex);
  39. if (mathcer.Success)
  40. {
  41. atacked.Add(mathcer.Groups[1].Value);
  42. continue;
  43. }
  44.  
  45. mathcer = Regex.Match(planet, defenderRegex);
  46. if (mathcer.Success)
  47. {
  48. destroyed.Add(mathcer.Groups[1].Value);
  49. }
  50. }
  51.  
  52. Console.WriteLine($"Attacked planets: {atacked.Count}");
  53. atacked.OrderBy(p=>p).ToList().ForEach(p => Console.WriteLine($"-> {p}"));
  54.  
  55. Console.WriteLine($"Destroyed planets: {destroyed.Count}");
  56. destroyed.OrderBy(p=>p).ToList().ForEach(p => Console.WriteLine($"-> {p}"));
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement