Advertisement
Lusien_Lashans

Monobilliard

Feb 6th, 2017
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Monobilliards
  5. {
  6.     public class Monobilliards : IMonobilliards
  7.     {
  8.         public bool IsCheater(IList<int> inspectedBalls)
  9.         {
  10.             var stack = new Stack<int>();
  11.             var queue = new Queue<int>();
  12.  
  13.             foreach (var ball in inspectedBalls)
  14.                 queue.Enqueue(ball);
  15.  
  16.             for (int i = 1; i < inspectedBalls.Count+1; i++)
  17.             {
  18.                 stack.Push(i);
  19.                 while (stack.Peek() == queue.Peek())
  20.                 {
  21.                     stack.Pop();
  22.                     queue.Dequeue();
  23.                     if ((stack.Count == 0) || (queue.Count == 0))
  24.                         break;
  25.                 }
  26.             }
  27.             return (stack.Count != 0);
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement