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 Problem_1.Reverse_Numbers_with_a_Stack
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- var stack = new Stack<long>();
- stack.Push(1);
- stack.Push(1);
- for (int i = 0; i <n-1; i++)
- {
- if (stack.Count==n)
- {
- break;
- }
- long fibOne = stack.Pop();
- long fibTwo = stack.Peek();
- stack.Push(fibOne);
- stack.Push(fibOne + fibTwo);
- }
- Console.WriteLine(stack.Pop());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement