Advertisement
FlushBG

Number Sequence with Queue

Jan 23rd, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 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 p05CreateSequenceWithQueue
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             decimal S1 = decimal.Parse(Console.ReadLine());            
  14.             var dynamicSequence = new Queue<decimal>();
  15.             var resultSequence = new Queue<decimal>();
  16.             resultSequence.Enqueue(S1);
  17.  
  18.             int stepCounter = 1;
  19.  
  20.             for (int i = 1; i < 50; i++)
  21.             {                
  22.                 switch (stepCounter)
  23.                 {
  24.                     case 0:                        
  25.                         S1 = dynamicSequence.Dequeue();
  26.                         stepCounter++;
  27.                         goto case 1;
  28.                     case 1:
  29.                         decimal S2 = S1 + 1;
  30.                         dynamicSequence.Enqueue(S2);
  31.                         resultSequence.Enqueue(S2);
  32.                         stepCounter++;
  33.                         break;
  34.  
  35.                     case 2:
  36.                         decimal S3 = 2 * S1 + 1;
  37.                         dynamicSequence.Enqueue(S3);
  38.                         resultSequence.Enqueue(S3);
  39.                         stepCounter++;
  40.                         break;
  41.  
  42.                     case 3:
  43.                         decimal S4 = S1 + 2;
  44.                         dynamicSequence.Enqueue(S4);
  45.                         resultSequence.Enqueue(S4);
  46.                         stepCounter = 0;
  47.                         break;
  48.                 }
  49.             }
  50.            
  51.             for (int i = 0; i < 50; i++)
  52.             {
  53.                 Console.Write($"{resultSequence.Dequeue()} ");
  54.             }
  55.             Console.WriteLine();
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement