Advertisement
social1986

Untitled

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