using System.Collections;
using System.Collections.Generic;
public int EvalExpression (List<char> s) {
int digit1 = 0, digit2 = 0, res = 0;
foreach (char j in st.ToArray()) {
List<int> temp = new List<int>();
temp.Add(Convert.ToInt32(st2.Pop()) - '0');
st2.Push(Convert.ToInt32(string.Join("", temp)));
List<int> temp = new List<int>();
temp.Add(Convert.ToInt32(st2.Pop()) - '0');
st2.Push(Convert.ToInt32(string.Join("", temp)));
List<int> temp = new List<int>();
temp.Add(Convert.ToInt32(st2.Pop()) - '0');
st2.Push(Convert.ToInt32(string.Join("", temp)));
List<int> temp = new List<int>();
temp.Add(Convert.ToInt32(st2.Pop()) - '0');
st2.Push(Convert.ToInt32(string.Join("", temp)));
if (j != '*' && j != '/' && j != '+' && j != '-')
List<int> temp2 = new List<int>();
temp2.Add(Convert.ToInt32(st2.Pop()) - '0');
st2.Push(Convert.ToInt32(string.Join("", temp2)));
digit1 = Convert.ToInt32(st2.Pop());
digit2 = Convert.ToInt32(st2.Pop());
public int EvalRPN(string[] tokens) {
for (int i = 0; i < tokens.Length; i++)
foreach (string j in st.ToArray()) {
if (j == "*" || j == "/" || j == "+" || j == "-") {
object digit2 = st2.Pop();
object digit1 = st2.Pop();
st2.Push("(" + digit1.ToString() + j + digit2.ToString() + ")");
string str = st2.Pop().ToString();
foreach (var k in str.ToCharArray()) {
List<char> arr = new List<char>();
while ((char)st2.Peek() != '(') {
var elem = (char)st2.Pop();
st2.Push(EvalExpression(arr));
public static void Main()
string[] tokens = {"12","121","+","3","*"};
Console.WriteLine(e.EvalRPN(tokens));