Advertisement
Guest User

Sequence with Queue

a guest
Jan 24th, 2018
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 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 Sequence_with_Queue
  8. {
  9. class SequenecQueu
  10. {
  11. static void Main(string[] args)
  12. {
  13. long S1 = long.Parse(Console.ReadLine());
  14. Queue<long> queue = new Queue<long>();
  15. Queue<long> resultForPrint = new Queue<long>();
  16. queue.Enqueue(S1);
  17.  
  18. StringBuilder sb = new StringBuilder();
  19. while (resultForPrint.Count <= 50)
  20. {
  21. if (resultForPrint.Count == 50)
  22. {
  23. for (int i = 0; i < 50; i++)
  24. {
  25. sb.Append(resultForPrint.Dequeue().ToString());
  26. sb.Append(" ");
  27. }
  28. Console.WriteLine(sb.ToString());
  29. break;
  30. }
  31. queue.Enqueue(queue.Peek() + 1);
  32. queue.Enqueue(queue.Peek() * 2 + 1);
  33. queue.Enqueue(queue.Peek() + 2);
  34. resultForPrint.Enqueue(queue.Dequeue());
  35. }
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement