Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Problem_2___Hornet_Comm
- {
- class Program
- {
- static void Main(string[] args)
- {
- var input = Console.ReadLine().Split(new string[] { " <-> " }, StringSplitOptions.RemoveEmptyEntries);
- var broadcasts = new List<string>();
- var massage = new List<string>();
- string check = "Broadcast";
- while (input[0] != "Hornet is Green")
- {
- if (input.Length > 1)
- {
- var firstPartOfInput = input[0].TrimEnd();
- var secondPartOfInput = input[1].Trim();
- if (IsNumber(firstPartOfInput) && IsContainingOnlyDigitsAndLetters(secondPartOfInput))
- {
- var result = firstPartOfInput.ToCharArray().Reverse().ToArray();
- var recipientCode = new string(result);
- massage.Add(recipientCode);
- massage.Add(secondPartOfInput);
- }
- else if (IsNotDigit(firstPartOfInput) && IsContainingOnlyDigitsAndLetters(secondPartOfInput))
- {
- var changedLetters = ChangingLetters(secondPartOfInput);
- broadcasts.Add(changedLetters);
- broadcasts.Add(firstPartOfInput);
- }
- }
- input = Console.ReadLine().Split(new string[] { " <-> " }, StringSplitOptions.RemoveEmptyEntries);
- }
- Console.WriteLine("Broadcasts:");
- PrintResult(broadcasts);
- Console.WriteLine("Messages:");
- PrintResult(massage);
- }
- public static bool IsNumber(string input)
- {
- for (int i = 0; i < input.Length; i++)
- {
- if (char.IsDigit(input[i]))
- {
- continue;
- }
- else
- {
- return false;
- }
- }
- return true;
- }
- public static bool IsContainingOnlyDigitsAndLetters(string input)
- {
- for (int i = 0; i < input.Length; i++)
- {
- if (char.IsLetter(input[i]) || char.IsDigit(input[i]))
- {
- continue;
- }
- else
- {
- return false;
- }
- }
- return true;
- }
- public static bool IsNotDigit(string input)
- {
- for (int i = 0; i < input.Length; i++)
- {
- if (char.IsDigit(input[i]))
- {
- return false;
- }
- }
- return true;
- }
- public static string ChangingLetters(string input)
- {
- var result = "";
- for (int i = 0; i < input.Length; i++)
- {
- if (char.IsDigit(input[i]))
- {
- result += input[i];
- continue;
- }
- if (char.IsLower(input[i]))
- {
- result += char.ToUpper(input[i]);
- }
- else if (char.IsUpper(input[i]))
- {
- result += char.ToLower(input[i]);
- }
- }
- return result;
- }
- public static void PrintResult(List<string> input)
- {
- var index = 0;
- for (int i = 0; i < input.Count/2; i++)
- {
- Console.WriteLine($"{input[index]} -> {input[index+1]}");
- index += 2;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement