Advertisement
dobroslav-atanasov

Untitled

Jan 27th, 2018
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 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 Problem_1.Reverse_Numbers_with_a_Stack
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.             var stack = new Stack<long>();
  15.  
  16.             stack.Push(1);
  17.             stack.Push(1);    
  18.  
  19.             for (int i = 0; i <n-1; i++)
  20.             {                
  21.                 if (stack.Count==n)
  22.                 {
  23.                     break;
  24.                 }
  25.                 long fibOne = stack.Pop();
  26.                 long fibTwo = stack.Peek();
  27.                 stack.Push(fibOne);
  28.                 stack.Push(fibOne + fibTwo);
  29.             }            
  30.                 Console.WriteLine(stack.Pop());            
  31.         }    
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement