Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Text.RegularExpressions;
  7. namespace _04.Star_Enigma
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int numPlanetsAttacked = 0;
  14. int numPlanetsDestroyed = 0;
  15. List<string> listPlanetsAttacked = new List<string>();
  16. List<string> listPlanetsDestroyed = new List<string>();
  17.  
  18. int num = int.Parse(Console.ReadLine());
  19.  
  20. for (int i = 0; i < num; i++)
  21. {
  22. string input = Console.ReadLine();
  23. string inputDecrypted = string.Empty;
  24. string toAdd = string.Empty;
  25.  
  26. string patternSTAR = @"[STARstar]";
  27.  
  28. MatchCollection collectionOfKeys = Regex.Matches(input, patternSTAR);
  29.  
  30. for (int j = 0; j < input.Length; j++)
  31. {
  32. inputDecrypted += (char)((int)input[j] - collectionOfKeys.Count);
  33. }
  34.  
  35. string patternALL = @"(@([A-Za-z]+)([^@\-!:>]))(\:\d+)(![A|D]!)(->\d+)";
  36.  
  37. Regex regexALL = new Regex(patternALL);
  38.  
  39. bool isMatch = regexALL.IsMatch(inputDecrypted);
  40.  
  41. if (isMatch)
  42. {
  43. Match match = regexALL.Match(inputDecrypted);
  44.  
  45. string str = match.Groups[3].Value;
  46. char chr = str[0];
  47.  
  48. if (match.Groups[5].ToString() == "!A!")
  49. {
  50. if ((int)chr >= 97 && (int)chr <= 122)
  51. {
  52. toAdd = match.Groups[2].ToString() + match.Groups[3].ToString();
  53. }
  54. else
  55. {
  56. toAdd = match.Groups[2].ToString();
  57. }
  58. numPlanetsAttacked++;
  59. listPlanetsAttacked.Add(toAdd);
  60. }
  61. else if (match.Groups[5].ToString() == "!D!")
  62. {
  63. if ((int)chr >= 97 && (int)chr <= 122)
  64. {
  65. toAdd = match.Groups[2].ToString() + match.Groups[3].ToString();
  66. }
  67. else
  68. {
  69. toAdd = match.Groups[2].ToString();
  70. }
  71. numPlanetsDestroyed++;
  72. listPlanetsDestroyed.Add(toAdd);
  73. }
  74. }
  75. }
  76.  
  77. listPlanetsAttacked.Sort();
  78. listPlanetsDestroyed.Sort();
  79.  
  80. Console.WriteLine($"Attacked planets: {numPlanetsAttacked}");
  81. foreach (var item in listPlanetsAttacked)
  82. {
  83. Console.WriteLine($"-> {item}");
  84. }
  85. Console.WriteLine($"Destroyed planets: {numPlanetsDestroyed}");
  86. foreach (var itemz in listPlanetsDestroyed)
  87. {
  88. Console.WriteLine($"-> {itemz}");
  89. }
  90. }
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement