Advertisement
Filkolev

BitsKiller

Jun 16th, 2014
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. using System;
  2.  
  3. class BitsKiller
  4. {
  5.     static void Main()
  6.     {
  7.         int n = int.Parse(Console.ReadLine());
  8.         int step = int.Parse(Console.ReadLine());
  9.  
  10.         string initial = null;
  11.         string result = null;
  12.  
  13.         for (int i = 0; i < n; i++)
  14.         {
  15.             int currentByte = int.Parse(Console.ReadLine());
  16.             initial = initial + Convert.ToString(currentByte, 2).PadLeft(8, '0');
  17.         }
  18.  
  19.         for (int i = 0; i < initial.Length; i++)
  20.         {
  21.             if (i%step == 1)
  22.             {
  23.                 continue;
  24.             }
  25.  
  26.             result = result + initial[i];
  27.          
  28.         }
  29.  
  30.         if (result.Length%8 != 0)
  31.         {
  32.             int padding = 8 - result.Length % 8;
  33.             result = result.PadRight(result.Length + padding,'0');
  34.         }
  35.  
  36.         for (int i = 0; i + 7 <= result.Length; i+=8)
  37.         {
  38.             string outputByte = result.Substring(i, 8);
  39.             int output = Convert.ToInt32(outputByte, 2);
  40.             Console.WriteLine(output);
  41.         }
  42.  
  43.  
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement