Пример #1
0
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').ToArray();
            int n     = int.Parse(Console.ReadLine());

            Queue <string> kids = new Queue <string>();

            for (int i = 0; i < input.Length; i++)
            {
                kids.Enqueue(input[i]); //vkarvame vuv opashkata
            }

            int cycle = 1;

            while (kids.Count > 1)                    //broim za da ostane edin element v opashkata
            {
                for (int i = 0; i < n - 1; i++)       //cikul do n
                {
                    string reminder = kids.Dequeue(); //vadim purvia elemen ot opashkata
                    kids.Enqueue(reminder);           //vkarvame go na posledno misto v opashkata
                }
                if (PrimeTool.IsPrime(cycle))
                {
                    Console.WriteLine($"Prime {kids.Peek()}");
                }
                else
                {
                    Console.WriteLine("Removed " + kids.Dequeue());
                }
                cycle++;
            }
            Console.WriteLine("Last is " + kids.Dequeue());
        }
Пример #2
0
        static void Main(string[] args)
        {
            var            children = Console.ReadLine().Split();
            var            number   = int.Parse(Console.ReadLine());
            int            cycle    = 1;
            Queue <string> queue    = new Queue <string>(children);

            while (queue.Count != 1)
            {
                for (int i = 1; i < number; i++)
                {
                    queue.Enqueue(queue.Dequeue());
                }
                if (PrimeTool.IsPrime(cycle))
                {
                    Console.WriteLine($"Prime {queue.Peek()}");
                }
                else
                {
                    Console.WriteLine($"Removed {queue.Dequeue()}");
                }
                cycle++;
            }
            Console.WriteLine($"Last is {queue.Dequeue()}");
        }