Advertisement
gabi11

Stacks and Queues - 6. Hot Potato

May 10th, 2019
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6. namespace Advanced
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             var input = Console.ReadLine().Split();
  13.             int number = int.Parse(Console.ReadLine());
  14.             var kids = new Queue<string>(input);
  15.  
  16.             while (kids.Count > 1)
  17.             {
  18.                 for (int i = 1; i < number; i++)
  19.                 {
  20.                     kids.Enqueue(kids.Dequeue());
  21.                 }
  22.                 Console.WriteLine($"Removed {kids.Dequeue()}");
  23.             }
  24.             Console.WriteLine($"Last is {kids.Dequeue()}");
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement