MilenaPetkanova

02_HornetComm_100/100

Nov 2nd, 2017
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class HornetComm
  5. {
  6. static void Main()
  7. {
  8. List<string> messages = new List<string>();
  9. List<string> broadcast = new List<string>();
  10.  
  11. string input = Console.ReadLine();
  12.  
  13. while (input != "Hornet is Green")
  14. {
  15. var tokens = input.Split(new string[] { " <-> " }, StringSplitOptions.None);
  16.  
  17. if (tokens.Length != 2)
  18. {
  19. input = Console.ReadLine();
  20. continue;
  21. }
  22. char[] firstQuery = tokens[0].ToCharArray();
  23. char[] secondQuery = tokens[1].ToCharArray();
  24.  
  25. bool isPrivateMessage = true;
  26. bool isBroadcast = false;
  27.  
  28. for (int i = 0; i < firstQuery.Length; i++)
  29. {
  30. bool isDigit = Char.IsDigit(firstQuery[i]);
  31. if (isDigit == false)
  32. {
  33. isPrivateMessage = false;
  34. break;
  35. }
  36. }
  37.  
  38. for (int i = 0; i < firstQuery.Length; i++)
  39. {
  40. bool isDigit = Char.IsDigit(firstQuery[i]);
  41. if (isDigit == true)
  42. {
  43. isBroadcast = false;
  44. break;
  45. }
  46. else
  47. {
  48. isBroadcast = true;
  49. }
  50. }
  51.  
  52. for (int i = 0; i < secondQuery.Length; i++)
  53. {
  54. bool isDigitOrLetter = Char.IsLetterOrDigit(secondQuery[i]);
  55. if (isDigitOrLetter == false)
  56. {
  57. isBroadcast = false;
  58. isPrivateMessage = false;
  59. break;
  60. }
  61. }
  62.  
  63. if (isPrivateMessage == true)
  64. {
  65. Array.Reverse(firstQuery);
  66. string firstQueryStr = new string(firstQuery);
  67. string secondQueryStr = new string(secondQuery);
  68. string messageStr = firstQueryStr + " -> " + secondQueryStr;
  69. messages.Add(messageStr);
  70. }
  71.  
  72. if (isBroadcast == true)
  73. {
  74. for (int i = 0; i < secondQuery.Length; i++)
  75. {
  76. bool isLetter = char.IsLetter(secondQuery[i]);
  77. bool isUpper = char.IsUpper(secondQuery[i]);
  78. bool isLower = char.IsLower(secondQuery[i]);
  79. if (isLetter && isUpper)
  80. {
  81. secondQuery[i] = char.ToLower(secondQuery[i]);
  82. }
  83. else if (isLetter && isLower)
  84. {
  85. secondQuery[i] = char.ToUpper(secondQuery[i]);
  86. }
  87. }
  88. string firstQueryStr = new string(firstQuery);
  89. string secondQueryStr = new string(secondQuery);
  90. string broadcastStr = secondQueryStr + " -> " + firstQueryStr;
  91. broadcast.Add(broadcastStr);
  92. }
  93.  
  94. input = Console.ReadLine();
  95. }
  96.  
  97. Console.WriteLine("Broadcasts:");
  98. if (broadcast.Count != 0)
  99. {
  100. foreach (string line in broadcast)
  101. {
  102. Console.WriteLine(line);
  103. }
  104. }
  105. else
  106. {
  107. Console.WriteLine("None");
  108. }
  109.  
  110. Console.WriteLine("Messages:");
  111. if (messages.Count != 0)
  112. {
  113. foreach (string line in messages)
  114. {
  115. Console.WriteLine(line);
  116. }
  117. }
  118. else
  119. {
  120. Console.WriteLine("None");
  121. }
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment