Advertisement
YavorGrancharov

Decode_Radio_Frequencies

Jul 2nd, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Decode_Radio_Frequencies
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             decimal[] input = Console.ReadLine().Split(' ').Select(decimal.Parse).ToArray();
  12.  
  13.             List<string> output = new List<string>();
  14.  
  15.             decimal left = 0;
  16.             decimal right = 0;
  17.             for (int i = 0; i < input.Length; i++)
  18.             {
  19.                 left = Math.Truncate(input[i]);
  20.                 right = input[i] - left;
  21.                 if (left > 0)
  22.                 {
  23.                     output.Insert(i, left.ToString());
  24.                 }
  25.                 if (right > 0)
  26.                 {
  27.                     output.Insert(i + 1, right.ToString().TrimStart('0').TrimStart('.'));
  28.                 }
  29.             }
  30.  
  31.             List<int> asInt = output.Select(s => Convert.ToInt32(s)).ToList();
  32.  
  33.             char converted = '\0';
  34.             string concat = string.Empty;
  35.             for (int i = 0; i < asInt.Count; i++)
  36.             {
  37.                 converted = Convert.ToChar(asInt[i]);
  38.                 concat += converted;
  39.             }
  40.             Console.WriteLine(concat);
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement