Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace BitsKiller
- {
- class BitsKiller
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- int step = int.Parse(Console.ReadLine());
- int[] numbers = new int[n];
- for (int i = 0; i < n; i++)
- {
- numbers[i] = int.Parse(Console.ReadLine());
- }
- List<string> collectedBinaries = new List<string>();
- for (int i = 0; i < numbers.Length; i++)
- {
- string tempBinNum = Convert.ToString(numbers[i], 2).PadLeft(8, '0');
- for (int j = 0; j < tempBinNum.Length; j++)
- {
- collectedBinaries.Add(tempBinNum[j].ToString());
- }
- }
- for (int i = 1,j=1; i < collectedBinaries.Count; i=1+(step*j),j++)
- {
- collectedBinaries[i]="-1";
- }
- List<string> final = new List<string>();
- foreach (var x in collectedBinaries)
- {
- if (x != "-1")
- {
- final.Add(x);
- }
- }
- if (final.Count%8!=0)
- {
- for (int i = 0; i < final.Count%8; i++)
- {
- final.Add("0");
- }
- }
- string joined = string.Join("", final);
- var finalBinary = Split(joined, 8);
- foreach (var f in finalBinary)
- {
- Console.WriteLine(Convert.ToInt32(f, 2));
- }
- }
- static IEnumerable<string> Split(string str, int chunkSize)
- {
- int len = str.Length;
- return Enumerable.Range(0, len / chunkSize).Select(i => str.Substring(i * chunkSize, chunkSize));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment