Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- int step = int.Parse(Console.ReadLine());
- int[,] input = new int[n, 8];
- int countOfBits = (n * 8 - 1) / step + 1;
- if(countOfBits % 8 != 0)
- countOfBits += 8 - countOfBits % 8;
- int[] output = new int[countOfBits];
- int[] preoutput = new int[n * 8];
- for (int i = 0; i < n; i++)
- {
- int number = int.Parse(Console.ReadLine());
- for (int j = 0; j < 8; j++)
- {
- if (number % 2 == 0)
- {
- input[i, j] = 0;
- }
- else
- input[i, j] = 1;
- number /= 2;
- }
- }
- for (int i = 0, index = 0; i < n; i++)
- {
- for (int j = 7; j >= 0; j--, index++)
- {
- preoutput[index] = input[i, j];
- }
- }
- for (int i = countOfBits - 1, j = 1; i >=0 ; i--)
- {
- if (j < preoutput.Length)
- {
- output[i] = preoutput[j];
- j += step;
- }
- else
- output[i] = 0;
- }
- for (int i = output.Length / 8 - 1 ; i >=0 ; i--)
- {
- int result = 0;
- for (int j = 0 + i * 8; j < 8 + (i * 8); j++)
- {
- if (output[j] == 1)
- result += (int)Math.Pow(2, j - i * 8);
- }
- Console.WriteLine(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement