-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask5.cs
52 lines (48 loc) · 1.63 KB
/
Task5.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using CodEx;
namespace ConsoleApplication5
{
class Task5
{
static void Main(string[] args)
{
List<string> p = new List<string>();
List<string> s = new List<string>();
p.InsertRange(0, Reader.Console().Line().Trim().Split());
p.Reverse();
int o1, o2;
foreach (string e in p)
switch (e)
{
case "+":
case "-":
case "*":
case "/":
if (Int32.TryParse(s[s.Count - 1], out o1) && Int32.TryParse(s[s.Count - 2], out o2))
{
s.RemoveAt(s.Count - 1);
s.RemoveAt(s.Count - 1);
if (e.Equals("+"))
s.Add(o1 + o2 + "");
if (e.Equals("-"))
s.Add(o1 - o2 + "");
if (e.Equals("*"))
s.Add(o1 * o2 + "");
if (e.Equals("/"))
s.Add(o1 / o2 + "");
}
else
{
Console.Write("ERROR");
return;
}
break;
default:
s.Add(e);
break;
}
Console.Write(s[0]);
}
}
}