Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Simple_Calculator
- {
- class SimpleCalculator
- {
- static void Main(string[] args)
- {
- Stack<string> calc = new Stack<string>(Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Reverse());
- while (calc.Count > 1)
- {
- int oper1 = int.Parse(calc.Pop());
- string action = calc.Pop();
- int oper2 = int.Parse(calc.Pop());
- if (action.Equals("+"))
- {
- calc.Push((oper1 + oper2).ToString());
- }
- else if (action.Equals("-"))
- {
- calc.Push((oper1 - oper2).ToString());
- }
- }
- Console.WriteLine(calc.Pop());
- }
- }
- }
Advertisement
RAW Paste Data
Copied
Advertisement