fbinnzhivko

SaltAndPepper 1

Apr 22nd, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2. class SaltAndPepper
  3. {
  4.     static void Main()
  5.     {
  6.         ulong number = ulong.Parse(Console.ReadLine());
  7.         string command = Console.ReadLine();
  8.  
  9.         while (command != "end")
  10.         {
  11.             string[] commandElements = command.Split(' ');
  12.             string action = commandElements[0];
  13.             int step = int.Parse(commandElements[1]);
  14.  
  15.             if (action == "salt")
  16.             {
  17.                 for (int i = 0; i <= 63; i += step)
  18.                 {
  19.                     if (((number >> i) & 1) == 1)
  20.                     {
  21.                         ulong mask = ~((ulong)1 << i);
  22.                         number = number & mask;
  23.                     }
  24.                 }
  25.             }
  26.             else
  27.             {
  28.                 for (var i = 0; i <= 63; i += step)
  29.                 {
  30.                     if (((number >> i) & 1) == 0)
  31.                     {
  32.                         ulong mask = (ulong)1 << i;
  33.                         number = number | mask;
  34.                     }
  35.                 }
  36.             }
  37.             command = Console.ReadLine();
  38.         }
  39.         Console.WriteLine(number);
  40.     }
  41. }
Add Comment
Please, Sign In to add comment