Advertisement
Guest User

Untitled

a guest
May 27th, 2017
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace CalculateSequenceWithQueue
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Queue<int> seqTemp = new Queue<int>();
  11.             Queue<int> seqPrint = new Queue<int>();
  12.  
  13.             int N = int.Parse(Console.ReadLine());
  14.             seqTemp.Enqueue(N);
  15.             while(seqPrint.Count<=49)
  16.             {
  17.                 seqTemp.Enqueue(seqTemp.Peek() + 1);
  18.                 seqTemp.Enqueue(2*seqTemp.Peek() + 1);
  19.                 seqTemp.Enqueue(seqTemp.Peek() + 2);
  20.                 seqPrint.Enqueue(seqTemp.Dequeue());
  21.             }
  22.             while (seqPrint.Count > 0)
  23.             {
  24.                 Console.Write(seqPrint.Dequeue()+" ");
  25.             }
  26.             Console.WriteLine();
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement