Advertisement
MilenaPetkanova

02_HornetComm_26022017

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