Advertisement
simonradev

QueueSeq

May 31st, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace CalculateSequanceWithQueue
  8. {
  9.     class QueueSeqTest
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             long startNumber = long.Parse(Console.ReadLine());
  14.  
  15.             Queue<long> sequance = new Queue<long>();
  16.             sequance.Enqueue(startNumber);
  17.  
  18.             StringBuilder result = new StringBuilder();
  19.  
  20.             int counter = 0;
  21.             while (counter != 50)
  22.             {
  23.                 long currNum = sequance.Dequeue();
  24.  
  25.                 result.Append(currNum + " ");
  26.  
  27.                 sequance.Enqueue(currNum + 1);
  28.                 sequance.Enqueue((currNum * 2) + 1);
  29.                 sequance.Enqueue(currNum + 2);
  30.                 counter++;
  31.             }
  32.  
  33.             Console.WriteLine(result.ToString());
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement