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;
- namespace _05_SaltAndPepper
- {
- class SaltAndPepper
- {
- static void Main(string[] args)
- {
- ulong number = ulong.Parse(Console.ReadLine());
- string command = Console.ReadLine();
- string binaryNumber = Convert.ToString((long)number, 2).PadLeft(64, '0');
- string newBinaryNumber = binaryNumber;
- while (command != "end")
- {
- char[] binaryArray = newBinaryNumber.ToCharArray();
- string[] commandArray = command.Split();
- string spice = commandArray[0]; //
- int step = int.Parse(commandArray[1]); // koq pozicija da pravim 0
- for (int i = 0; i < binaryNumber.Length; i += step)
- {
- if (spice == "salt")
- {
- binaryArray[63-i] = '0';
- newBinaryNumber = new string(binaryArray);
- }
- else if (spice == "pepper")
- {
- binaryArray[63-i] = '1';
- newBinaryNumber = new string(binaryArray);
- }
- }
- command = Console.ReadLine();
- }
- long newDecimalNumber = Convert.ToInt64(newBinaryNumber, 2);
- Console.WriteLine(newDecimalNumber);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement