Advertisement
sivancheva

SaltAndPepper

Jun 21st, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _05_SaltAndPepper
  8. {
  9. class SaltAndPepper
  10. {
  11. static void Main(string[] args)
  12. {
  13. ulong number = ulong.Parse(Console.ReadLine());
  14. string command = Console.ReadLine();
  15.  
  16. string binaryNumber = Convert.ToString((long)number, 2).PadLeft(64, '0');
  17. string newBinaryNumber = binaryNumber;
  18.  
  19.  
  20. while (command != "end")
  21. {
  22. char[] binaryArray = newBinaryNumber.ToCharArray();
  23.  
  24. string[] commandArray = command.Split();
  25. string spice = commandArray[0]; //
  26. int step = int.Parse(commandArray[1]); // koq pozicija da pravim 0
  27.  
  28. for (int i = 0; i < binaryNumber.Length; i += step)
  29. {
  30.  
  31. if (spice == "salt")
  32. {
  33.  
  34. binaryArray[63-i] = '0';
  35. newBinaryNumber = new string(binaryArray);
  36.  
  37. }
  38. else if (spice == "pepper")
  39. {
  40. binaryArray[63-i] = '1';
  41. newBinaryNumber = new string(binaryArray);
  42. }
  43. }
  44.  
  45. command = Console.ReadLine();
  46. }
  47.  
  48.  
  49. long newDecimalNumber = Convert.ToInt64(newBinaryNumber, 2);
  50. Console.WriteLine(newDecimalNumber);
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement