Advertisement
social1986

Untitled

Oct 28th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 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.  
  7. namespace Problem_2___Hornet_Comm
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var input = Console.ReadLine().Split(new string[] { " <-> " }, StringSplitOptions.RemoveEmptyEntries);
  14. var broadcasts = new List<string>();
  15. var massage = new List<string>();
  16. string check = "Broadcast";
  17.  
  18. while (input[0] != "Hornet is Green")
  19. {
  20. if (input.Length > 1)
  21. {
  22. var firstPartOfInput = input[0].TrimEnd();
  23. var secondPartOfInput = input[1].Trim();
  24.  
  25. if (IsNumber(firstPartOfInput) && IsContainingOnlyDigitsAndLetters(secondPartOfInput))
  26. {
  27. var result = firstPartOfInput.ToCharArray().Reverse().ToArray();
  28. var recipientCode = new string(result);
  29.  
  30. massage.Add(recipientCode);
  31. massage.Add(secondPartOfInput);
  32. }
  33. else if (IsNotDigit(firstPartOfInput) && IsContainingOnlyDigitsAndLetters(secondPartOfInput))
  34. {
  35. var changedLetters = ChangingLetters(secondPartOfInput);
  36. broadcasts.Add(changedLetters);
  37. broadcasts.Add(firstPartOfInput);
  38. }
  39. }
  40. input = Console.ReadLine().Split(new string[] { " <-> " }, StringSplitOptions.RemoveEmptyEntries);
  41. }
  42.  
  43. Console.WriteLine("Broadcasts:");
  44. PrintResult(broadcasts);
  45. Console.WriteLine("Messages:");
  46. PrintResult(massage);
  47.  
  48. }
  49.  
  50. public static bool IsNumber(string input)
  51. {
  52. for (int i = 0; i < input.Length; i++)
  53. {
  54. if (char.IsDigit(input[i]))
  55. {
  56. continue;
  57. }
  58. else
  59. {
  60. return false;
  61. }
  62. }
  63. return true;
  64. }
  65.  
  66. public static bool IsContainingOnlyDigitsAndLetters(string input)
  67. {
  68.  
  69. for (int i = 0; i < input.Length; i++)
  70. {
  71. if (char.IsLetter(input[i]) || char.IsDigit(input[i]))
  72. {
  73. continue;
  74. }
  75. else
  76. {
  77. return false;
  78. }
  79. }
  80. return true;
  81. }
  82.  
  83. public static bool IsNotDigit(string input)
  84. {
  85. for (int i = 0; i < input.Length; i++)
  86. {
  87. if (char.IsDigit(input[i]))
  88. {
  89. return false;
  90. }
  91. }
  92. return true;
  93. }
  94.  
  95. public static string ChangingLetters(string input)
  96. {
  97. var result = "";
  98. for (int i = 0; i < input.Length; i++)
  99. {
  100. if (char.IsDigit(input[i]))
  101. {
  102. result += input[i];
  103. continue;
  104. }
  105. if (char.IsLower(input[i]))
  106. {
  107. result += char.ToUpper(input[i]);
  108. }
  109. else if (char.IsUpper(input[i]))
  110. {
  111. result += char.ToLower(input[i]);
  112. }
  113. }
  114. return result;
  115. }
  116.  
  117. public static void PrintResult(List<string> input)
  118. {
  119. var index = 0;
  120. for (int i = 0; i < input.Count/2; i++)
  121. {
  122. Console.WriteLine($"{input[index]} -> {input[index+1]}");
  123. index += 2;
  124. }
  125. }
  126. }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement