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;
- //You are given an array of doubles (one line, space-separated). Your task is to convert the double values to their character //representations and insert them into a list like so:
- //• Example: 83.105
- //• Extract the left part of the number and convert it to its ASCII code representation: 83 S
- //• Extract the right part of the number and convert I to its ASCII code representation: 105 i
- //• Insert the left character at the position equal to the index of the double number in the original array. Index of double: 0 insert S at index 0
- //• Insert the right character at the position equal to the index of the double number in the original array, counted in reverse: index //of the double: 0 insert “i” at index 0, counted in reverse (so, the end of the list)
- //Repeat the aforementioned algorithm for each element of the double array, until you run out of elements. When you do, print the list //with no delimiter.
- //If any of the parts of the double number are 0 (such as 86.0 or 0.97), ignore them and do not insert them anywhere.
- namespace Decode_radio_frequences
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] frequences = Console.ReadLine().Split(' ').ToArray();
- List<char> result = new List<char>();
- for (int i = 0; i < frequences.Length; i++)
- {
- char left = TakeLeft(frequences[i]);
- char right = TakeRight(frequences[i]);
- if ((int)left != 0)
- {
- result.Insert(i, left);
- }
- if ((int)right != 0)
- {
- result.Insert(result.Count - i, right);
- }
- }
- Console.WriteLine(string.Join("", result));
- }
- static char TakeLeft(string left)
- {
- int[] leftRight = left.Split('.').Select(int.Parse).ToArray();
- int leftPart = leftRight[0];
- char leftChar = (char)leftPart;
- return leftChar;
- }
- static char TakeRight(string right)
- {
- int[] leftRight = right.Split('.').Select(int.Parse).ToArray();
- int rightPart = leftRight[1];
- char rightChar = (char)rightPart;
- return rightChar;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement