nadia_dr

Untitled

Aug 17th, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6.  
  7. class BitKiller
  8. {
  9.     static void Main()
  10.     {
  11.         int n = int.Parse(Console.ReadLine());
  12.         int step = int.Parse(Console.ReadLine());
  13.  
  14.         int[] bytes = new int[n];
  15.         string bits = "";
  16.  
  17.         for (int i = 0; i < n; i++)
  18.         {
  19.             bytes[i] = int.Parse(Console.ReadLine());
  20.             string alabala = Convert.ToString(bytes[i], 2).PadLeft(8, '0');
  21.             bits += alabala;
  22.         }
  23.  
  24.         char[] arrayOfBits = bits.ToCharArray();
  25.         int killPosition = 1;
  26.         int indexer = 1;
  27.         StringBuilder result = new StringBuilder();
  28.  
  29.         for (int i = 0; i < arrayOfBits.Length; i++)
  30.         {
  31.  
  32.             if (i != killPosition)
  33.             {
  34.  
  35.                 result.Append(arrayOfBits[i]);
  36.             }
  37.             else
  38.             {
  39.                 killPosition = (1+indexer * step);
  40.                 indexer++;
  41.             }
  42.  
  43.         }
  44.  
  45.         int pad=0;
  46.         if((result.Length % 8)==0)    
  47.         {
  48.             pad=(result.Length)/8;
  49.         }
  50.         else if(((result.Length) % 8)!=0)
  51.         {
  52.             pad = (result.Length / 8)+1;
  53.         }
  54.         string endResult = result.ToString().PadRight((pad * 8), '0');
  55.  
  56.         string[] endNumbers = new string[endResult.Length / 8];
  57.         int index = 0;
  58.  
  59.         for (int i = 0; i < endNumbers.Length; i++)
  60.         {
  61.             endNumbers[i] = endResult.Substring(index, 8);
  62.             index += 8;
  63.         }
  64.         for (int i = 0; i < endNumbers.Length; i++)
  65.         {
  66.             Console.WriteLine(Convert.ToInt32(endNumbers[i], 2));
  67.         }
  68.  
  69.     }  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment