Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _2._Simple_Calculator
- {
- public class Program
- {
- public static void Main()
- {
- var input = Console.ReadLine()
- .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- var stack = new Stack<string>(input);
- var sum = 0;
- while (stack.Count > 1)
- {
- var number = int.Parse(stack.Pop());
- var operand = stack.Pop();
- switch (operand)
- {
- case "-":
- sum -= number;
- break;
- case "+":
- sum += number;
- break;
- }
- }
- var number = int.Parse(stack.Pop());
- sum += number;
- Console.WriteLine(sum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement