marekov

Enigma

Jul 4th, 2020
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace Enigma
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11.             string[] decimalValues = ReadData();
  12.             List<string> binaryValues = new List<string>();
  13.             StringBuilder sb = new StringBuilder();
  14.  
  15.             for (int currIndex = 0; currIndex < decimalValues.Length; currIndex++)
  16.             {
  17.                 string currentValue = Convert.ToString(int.Parse(decimalValues[currIndex]), 2);
  18.                 currentValue = currentValue.PadLeft(8, '0');
  19.  
  20.                 binaryValues.Add(currentValue);
  21.             }
  22.  
  23.             for (int i = 0; i < binaryValues.Count; i++)
  24.             {
  25.                 string currentBinary = binaryValues[i];
  26.  
  27.                 if (i % 2 == 0)
  28.                 {
  29.                     for (int j = 0; j < currentBinary.Length; j++)
  30.                     {
  31.                         if (j % 2 != 0)
  32.                         {
  33.                             sb.Append(currentBinary[j]);
  34.                         }
  35.                     }
  36.                 }
  37.                 else
  38.                 {
  39.                     for (int j = 0; j < currentBinary.Length; j++)
  40.                     {
  41.                         if (j % 2 == 0)
  42.                         {
  43.                             sb.Append(currentBinary[j]);
  44.                         }
  45.                     }
  46.                 }
  47.             }
  48.             Console.WriteLine(sb.ToString());
  49.         }
  50.         public static string[] ReadData() => Console.ReadLine()
  51.             .Split(new[] { ',', ' ' });
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment