Advertisement
yana_neykovaa

Hornet Comm.

Dec 1st, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 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.  
  8. namespace _003.Hornet_Comm
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. string input = Console.ReadLine();
  15. string privateMessageRegex = "^([0-9]+) <-> ([A-Za-z0-9]+)$";
  16. string broadcastRegex = "^([0-9]+ <-> ([A-Za-z0-9]+)$";
  17.  
  18. List<string> messages = new List<string>();
  19. List<string> broadcasts = new List<string>();
  20.  
  21.  
  22. while (input != "Hornet is Green")
  23. {
  24. var privateMessageMatch = Regex.Match(input, privateMessageRegex);
  25. var broadcastMatch = Regex.Match(input, broadcastRegex);
  26.  
  27. if (privateMessageMatch.Success)
  28. {
  29. string recipientCode = privateMessageMatch.Groups[1].ToString();
  30. recipientCode = string.Join("", recipientCode.ToCharArray().Reverse().ToArray());
  31. messages.Add(recipientCode + " -> " + privateMessageMatch.Groups[2].ToString());
  32. }
  33.  
  34. if (broadcastMatch.Success)
  35. {
  36. string frequency = broadcastMatch.Groups[2].ToString();
  37. string frequencyResult = "";
  38. for (int i = 0; i < frequency.Length; i++)
  39. {
  40. if (char.IsLower(frequency[i]))
  41. {
  42. frequencyResult += frequency[i].ToString().ToUpper();
  43. }
  44. else if (char.IsUpper(frequency[i]))
  45. {
  46. frequencyResult += frequency[i].ToString().ToLower();
  47. }
  48. else
  49. {
  50. frequencyResult += frequency[i].ToString();
  51. }
  52.  
  53. }
  54. broadcasts.Add(frequencyResult + " -> " + broadcastMatch.Groups[1]);
  55. }
  56. input = Console.ReadLine();
  57. }
  58. Console.WriteLine("Broadcasts:");
  59. if (broadcasts.Count == 0)
  60. {
  61. Console.WriteLine("None");
  62. }
  63. else
  64. {
  65. broadcasts.ForEach(e => Console.WriteLine(e));
  66. }
  67.  
  68. Console.WriteLine("Messages:");
  69. if (messages.Count == 0)
  70. {
  71. Console.WriteLine("None");
  72. }
  73. else
  74. {
  75. messages.ForEach(e => Console.WriteLine(e));
  76. }
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement