Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace _02.HornetComm
- {
- class Broadcast
- {
- public string Frequency { get; set; }
- public string Message { get; set; }
- public static string ModifyFrequency(string secondQuery)
- {
- var newQuery = String.Empty;
- for (int index = 0; index < secondQuery.Length; index++)
- {
- var character = secondQuery[index];
- if(character >= 65 && character <= 90)
- {
- character = (char)(character + 32);
- }
- else if (character >= 97 && character <= 122)
- {
- character = (char)(character - 32);
- }
- newQuery += character;
- }
- return newQuery;
- }
- }
- class PrivateMessage
- {
- public string Recipient { get; set; }
- public string Message { get; set; }
- public static string ReverseRecipient(string firstQuery)
- {
- var newQuery = String.Empty;
- for (int index = firstQuery.Length - 1; index >= 0; index--)
- {
- newQuery += firstQuery[index];
- }
- return newQuery;
- }
- }
- class HornetComm
- {
- static void Main()
- {
- string input = Console.ReadLine();
- var privateMessages = new List<PrivateMessage>();
- var broadcasts = new List<Broadcast>();
- while (input != "Hornet is Green")
- {
- string[] splitInput = input.Split(new string[] { " <-> "},
- StringSplitOptions.None);
- string firstQuery = string.Empty;
- string secondQuery = string.Empty;
- bool isFirstOnlyDigits = false;
- bool isFirstWithoutDigits = false;
- bool isSecondWithDigisAndLetters = false;
- if (splitInput.Length > 1)
- {
- firstQuery = splitInput[0];
- secondQuery = splitInput[1];
- isFirstOnlyDigits = IsFirstQueryOnlyDigits(firstQuery);
- isFirstWithoutDigits = IsFirstQueryWithoutDigits(firstQuery);
- isSecondWithDigisAndLetters = IsSecondQueryWithDigitsAndLetters(secondQuery);
- }
- if(isFirstOnlyDigits && isSecondWithDigisAndLetters)
- {
- var message = new PrivateMessage()
- {
- Recipient = PrivateMessage.ReverseRecipient(firstQuery),
- Message = secondQuery,
- };
- privateMessages.Add(message);
- }
- else if(isFirstWithoutDigits && isSecondWithDigisAndLetters)
- {
- var broadcast = new Broadcast()
- {
- Frequency = Broadcast.ModifyFrequency(secondQuery),
- Message = firstQuery,
- };
- broadcasts.Add(broadcast);
- }
- input = Console.ReadLine();
- }
- PrintBroadcasts(broadcasts);
- PrintPrivateMessages(privateMessages);
- }
- static bool IsFirstQueryOnlyDigits(string firstQuery)
- {
- for (int index = 0; index < firstQuery.Length; index++)
- {
- char currentSymbol = firstQuery[index];
- if (currentSymbol < '0' || currentSymbol > '9')
- {
- return false;
- }
- }
- return true;
- }
- static bool IsFirstQueryWithoutDigits(string firstQuery)
- {
- for (int index = 0; index < firstQuery.Length; index++)
- {
- char currentSymbol = firstQuery[index];
- if (currentSymbol >= '0' && currentSymbol <= '9')
- {
- return false;
- }
- }
- return true;
- }
- static bool IsSecondQueryWithDigitsAndLetters(string secondQuery)
- {
- for (int index = 0; index < secondQuery.Length; index++)
- {
- char currentSymbol = secondQuery[index];
- if (currentSymbol < 48 || currentSymbol >= 123 ||
- (currentSymbol >= 58 && currentSymbol < 65) ||
- (currentSymbol >= 91 && currentSymbol < 97))
- {
- return false;
- }
- }
- return true;
- }
- static void PrintBroadcasts(List<Broadcast> broadcasts)
- {
- Console.WriteLine("Broadcasts:");
- if (broadcasts.Count == 0)
- {
- Console.WriteLine("None");
- }
- else
- {
- foreach (var broadcast in broadcasts)
- {
- string freq = broadcast.Frequency;
- string message = broadcast.Message;
- Console.WriteLine("{0} -> {1}", freq, message);
- }
- }
- }
- static void PrintPrivateMessages(List<PrivateMessage> privateMessages)
- {
- Console.WriteLine("Messages:");
- if (privateMessages.Count == 0)
- {
- Console.WriteLine("None");
- }
- else
- {
- foreach (var privateMessage in privateMessages)
- {
- string recipient = privateMessage.Recipient;
- string message = privateMessage.Message;
- Console.WriteLine("{0} -> {1}", recipient, message);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment