sivancheva

HornetComm

Oct 9th, 2017
177
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace _02_HornetComm
  9. {
  10. class HornetComm
  11. {
  12. static void Main(string[] args)
  13. {
  14. var input = Console.ReadLine();
  15. var messagePattern = new Regex(@"^([\d]+) <-> ([a-zA-Z0-9]+)$");
  16. var broadcastPattern = new Regex(@"^([^\d]+) <-> ([a-zA-Z0-9]+)$");
  17.  
  18. var messageResultList = new List<string>();
  19. var broadcastResultList = new List<string>();
  20.  
  21. while (input != "Hornet is Green")
  22. {
  23. var matchMessage = messagePattern.Match(input);
  24. var matchBroadcast = broadcastPattern.Match(input);
  25.  
  26. if (matchMessage.Success)
  27. {
  28. var messageArr = input.Split(new string[] { "<->" }, StringSplitOptions.RemoveEmptyEntries).Select(x=> x.Trim()).ToArray();
  29. var recipientChar = messageArr[0].ToCharArray();
  30. Array.Reverse(recipientChar);
  31.  
  32. var recipient = new string(recipientChar);
  33. var message = messageArr[1];
  34.  
  35. string resultMessage = recipient + " -> " + message;
  36. messageResultList.Add(resultMessage);
  37.  
  38. }
  39. else if (matchBroadcast.Success)
  40. {
  41. var broadcastArr = input.Split(new string[] { " <-> " }, StringSplitOptions.RemoveEmptyEntries);
  42.  
  43. var message = broadcastArr[0];
  44. var frequency = broadcastArr[1];
  45.  
  46. StringBuilder builder = new StringBuilder();
  47.  
  48. for (int i = 0; i < frequency.Length; i++)
  49. {
  50. char a = frequency[i];
  51. if (char.IsLower(a))
  52. {
  53. a = Char.ToUpper(a);
  54.  
  55. }
  56. else if (char.IsUpper(a))
  57. {
  58. a= Char.ToLower(a);
  59.  
  60. }
  61.  
  62. builder.Append(a);
  63. }
  64. string resultMessage = builder + " -> " + message;
  65. broadcastResultList.Add(resultMessage);
  66. }
  67. input = Console.ReadLine();
  68. }
  69. Console.WriteLine("Broadcasts:");
  70. if (broadcastResultList.Count == 0)
  71. {
  72. Console.WriteLine("None");
  73. }
  74. else
  75. {
  76. foreach (var broadcast in broadcastResultList)
  77. {
  78. Console.WriteLine(broadcast);
  79. }
  80. }
  81.  
  82. Console.WriteLine("Messages:");
  83.  
  84. if (messageResultList.Count == 0)
  85. {
  86. Console.WriteLine("None");
  87. }
  88. else
  89. {
  90. foreach (var privat in messageResultList)
  91. {
  92. Console.WriteLine(privat);
  93. }
  94. }
  95.  
  96.  
  97. }
  98. }
  99. }
RAW Paste Data