Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _05.BitsKiller
- {
- class Program
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- int step = int.Parse(Console.ReadLine());
- string sequence = String.Empty;
- // Concatenate binary representation to the string
- for (int i = 0; i < n; i++)
- {
- sequence += Convert.ToString(byte.Parse(Console.ReadLine()), 2).PadLeft(8, '0');
- }
- // remove the bits at the steps
- for (int st = 1; st < sequence.Length; st += step - 1)
- {
- sequence = sequence.Remove(st, 1);
- }
- // add the necessary 0s at the end so that sequence.Length % 8 = 0
- if (sequence.Length % 8 != 0)
- {
- sequence += new string('0', ((sequence.Length / 8) + 1) * 8 - sequence.Length);
- }
- // print result
- for (int i = 0; i < sequence.Length; i += 8)
- {
- int number = Convert.ToInt32(sequence.Substring(i, 8).PadRight(8, '0'), 2);
- Console.WriteLine(number);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement