krasi1105

Decode Radio Frees

Mar 3rd, 2017
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 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 frequencies
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] input = Console.ReadLine().Split();
  14.             StringBuilder left = new StringBuilder();
  15.             StringBuilder right = new StringBuilder();
  16.             foreach (string item in input)
  17.             {
  18.                 int dotIndex = DotIndex(item);
  19.                 char leftChar = (char)int.Parse(item.Substring(0, dotIndex));
  20.                 char rightChar = (char)int.Parse(item.Substring(dotIndex + 1));
  21.                 if (leftChar != 0)
  22.                 {
  23.                     left.Append(leftChar);
  24.                 }
  25.                 if (rightChar != 0)
  26.                 {
  27.                     right.Append(rightChar);
  28.                 }
  29.             }
  30.             string output = left.ToString() + new string(right.ToString().Reverse().ToArray());
  31.             Console.WriteLine(output);
  32.         }
  33.  
  34.         private static int DotIndex(string item)
  35.         {
  36.             for (int i = 0; i < item.Length; i++)
  37.             {
  38.                 if (item[i] == '.')
  39.                 {
  40.                     return i;
  41.                 }
  42.             }
  43.             throw new Exception("No dot found");
  44.         }
  45.     }
  46. }
Add Comment
Please, Sign In to add comment