Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace p05CreateSequenceWithQueue
- {
- class Program
- {
- static void Main(string[] args)
- {
- decimal S1 = decimal.Parse(Console.ReadLine());
- var dynamicSequence = new Queue<decimal>();
- var resultSequence = new Queue<decimal>();
- resultSequence.Enqueue(S1);
- int stepCounter = 1;
- for (int i = 1; i < 50; i++)
- {
- switch (stepCounter)
- {
- case 0:
- S1 = dynamicSequence.Dequeue();
- stepCounter++;
- goto case 1;
- case 1:
- decimal S2 = S1 + 1;
- dynamicSequence.Enqueue(S2);
- resultSequence.Enqueue(S2);
- stepCounter++;
- break;
- case 2:
- decimal S3 = 2 * S1 + 1;
- dynamicSequence.Enqueue(S3);
- resultSequence.Enqueue(S3);
- stepCounter++;
- break;
- case 3:
- decimal S4 = S1 + 2;
- dynamicSequence.Enqueue(S4);
- resultSequence.Enqueue(S4);
- stepCounter = 0;
- break;
- }
- }
- for (int i = 0; i < 50; i++)
- {
- Console.Write($"{resultSequence.Dequeue()} ");
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement