Guest User

Bits Inverter Three

a guest
Jun 16th, 2015
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. class BitsInverterTwo
  5. {
  6.     static void Main()
  7.     {
  8.         int n = int.Parse(Console.ReadLine());
  9.         int step = int.Parse(Console.ReadLine());
  10.         int index = 0;
  11.  
  12.         var binNumber = new StringBuilder();
  13.         for (int i = 0; i < n; i++)
  14.         {
  15.             binNumber.Append(Convert.ToString(int.Parse(Console.ReadLine()), 2).PadLeft(8, '0'));
  16.             for (int j = 0; j < binNumber.Length; j++)
  17.             {
  18.                 index++;
  19.                 if ((step == 1) || (index % step == 1))
  20.                 {
  21.                     if (binNumber[j] == '0')
  22.                     {
  23.                         binNumber[j] = '1';
  24.                     }
  25.                     else
  26.                     {
  27.                         binNumber[j] = '0';
  28.                     }  
  29.                 }              
  30.             }
  31.  
  32.             int intResult = Convert.ToInt32(binNumber.ToString(), 2);
  33.             Console.WriteLine(intResult);
  34.             binNumber.Clear();
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment