Exemple #1
0
        static void Main()
        {
            string         input = Console.ReadLine();
            int            num   = int.Parse(Console.ReadLine());
            Queue <string> queue = new Queue <string>(input.Split());

            int cycle = 1;

            while (queue.Count > 1)
            {
                for (int i = 1; i < num; 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()}");
        }
        static void Main(string[] args)
        {
            string[] children = Console.ReadLine().Split(' ');
            int      num      = int.Parse(Console.ReadLine());

            var queue = new Queue <string>(children);
            int cycle = 1;

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