Advertisement
Guest User

Untitled

a guest
Apr 14th, 2014
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _05.BitsKiller
  4. {
  5.     class Program
  6.     {
  7.         static void Main()
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.             int step = int.Parse(Console.ReadLine());
  11.             string sequence = String.Empty;
  12.  
  13.             // Concatenate binary representation to the string
  14.             for (int i = 0; i < n; i++)
  15.             {
  16.                 sequence += Convert.ToString(byte.Parse(Console.ReadLine()), 2).PadLeft(8, '0');
  17.             }
  18.             // remove the bits at the steps
  19.             for (int st = 1; st < sequence.Length; st += step - 1)
  20.             {
  21.                 sequence = sequence.Remove(st, 1);
  22.             }
  23.             // add the necessary 0s at the end so that sequence.Length % 8 = 0
  24.             if (sequence.Length % 8 != 0)
  25.             {
  26.                 sequence += new string('0', ((sequence.Length / 8) + 1) * 8 - sequence.Length);
  27.             }
  28.             // print result
  29.             for (int i = 0; i < sequence.Length; i += 8)
  30.             {
  31.                 int number = Convert.ToInt32(sequence.Substring(i, 8).PadRight(8, '0'), 2);
  32.                 Console.WriteLine(number);
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement