Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5. using System.Linq;
  6. namespace _3._Star_Enigma
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. int n = int.Parse(Console.ReadLine());
  13.  
  14. List<StringBuilder> decryptedMessages = new List<StringBuilder>();
  15. for (int i = 0; i < n; i++)
  16. {
  17. string messages = Console.ReadLine();
  18. string patternKey = @"[sStTaArR]";
  19. Regex regex = new Regex(patternKey);
  20. MatchCollection matches = regex.Matches(messages);
  21. int countDeleteAscii = matches.Count;
  22. StringBuilder decryptMessage = new StringBuilder();
  23. for (int j = 0; j < messages.Length; j++)
  24. {
  25. decryptMessage.Append(Convert.ToChar(messages[j] - countDeleteAscii));
  26. }
  27. decryptedMessages.Add(decryptMessage);
  28. }
  29. List<string> attacked = new List<string>();
  30. List<string> destryed = new List<string>();
  31. foreach (var item in decryptedMessages)
  32. {
  33. string[] splitting = item.ToString().Split(new[] {'@',':'}).ToArray();
  34. string name = splitting[1];
  35. string namePattern = @"[A-Za-z]+";
  36. Regex regexName = new Regex(namePattern);
  37. Match matchName = regexName.Match(name);
  38. if (!matchName.Success)
  39. {
  40. continue;
  41. }
  42. string patternPlanetPopulation = @"[0-9]+(?=!)";
  43. Regex regexPopulation = new Regex(patternPlanetPopulation);
  44. Match matchPopulation = regexPopulation.Match(splitting[2]);
  45.  
  46. if (!matchPopulation.Success)
  47. {
  48. continue;
  49. }
  50. string patternAttack = @"![A|D]!";
  51. Regex regexAttack = new Regex(patternAttack);
  52. Match matchAttack = regexAttack.Match(splitting[2]);
  53. if (!matchAttack.Success)
  54. {
  55. continue;
  56. }
  57. string patternSoldierCount = @"(?<=->)[0-9]*";
  58. Regex regexSoldiers = new Regex(patternSoldierCount);
  59. Match matchSoldiers = regexSoldiers.Match(splitting[2]);
  60. if (!matchSoldiers.Success)
  61. {
  62. continue;
  63. }
  64. if (matchAttack.ToString() == "!A!")
  65. {
  66. attacked.Add(matchName.ToString());
  67. }
  68. if (matchAttack.ToString() == "!D!")
  69. {
  70. destryed.Add(matchName.ToString());
  71. }
  72. }
  73. if (attacked.Count == 0)
  74. {
  75. Console.WriteLine("Attacked planets: 0");
  76. }
  77. else
  78. {
  79. Console.WriteLine($"Attacked planets: {attacked.Count}");
  80. foreach (var item in attacked)
  81. {
  82. Console.WriteLine($"-> {item}");
  83. }
  84. }
  85. if (destryed.Count == 0)
  86. {
  87. Console.WriteLine("Destroyed planets: 0");
  88. }
  89. else
  90. {
  91. Console.WriteLine($"Destroyed planets: {destryed.Count}");
  92. foreach (var item in destryed.OrderBy(x=>x))
  93. {
  94. Console.WriteLine($"-> {item}");
  95. }
  96. }
  97. }
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement