[Csharp]
Using System;
Using System. Collections;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Using System. Text. RegularExpressions;
Simple namespace expression
{
Class Program
{
Static void Main (string [] args)
{
Stack numbs = new Stack ();
Stack ops = new Stack ();
String expression = "5 + 10-15*20*2 ";
Calculate (numbs, ops, expression );
Console. WriteLine (numbs. Pop ());
}
Public static bool IsNumeric (string input)
{
Bool flag = true;
String pattern = "^ \ d + $ ";
Regex validate = new Regex (pattern );
If (! Validate. IsMatch (input ))
{
Flag = false;
}
Return flag;
}
Public static void Calculate (Stack n, Stack o, string exp)
{
String ch, token = "";
For (int p = 0; p <exp. Length; p ++)
{
Ch = exp. Substring (p, 1 );
If (IsNumeric (ch ))
{
Token + = ch;
}
If (ch = "" | p = (exp. Length-1 ))
{
If (IsNumeric (token ))
{
N. Push (token );
Token = "";
}
}
Else if (ch = "+" | ch = "-" | ch = "*" | ch = "/")
{
O. Push (ch );
}
If (n. Count = 2)
{
Compute (n, o );
}
}
}
Public static void Compute (Stack n, Stack o)
{
Int oper1, oper2;
String delimiter;
Oper1 = Convert. ToInt32 (n. Pop ());
Oper2 = Convert. ToInt32 (n. Pop ());
Topology = Convert. ToString (o. Pop ());
Switch)
{
Case "+ ":
N. Push (oper1 + oper2 );
Break;
Case "-":
N. Push (oper1-oper2 );
Break;
Case "*":
N. Push (oper1 * oper2 );
Break;
Case "/":
N. Push (oper1/oper2 );
Break;
}
}
}
}
Using System;
Using System. Collections;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Using System. Text. RegularExpressions;
Simple namespace expression
{
Class Program
{
Static void Main (string [] args)
{
Stack numbs = new Stack ();
Stack ops = new Stack ();
String expression = "5 + 10-15*20*2 ";
Calculate (numbs, ops, expression );
Console. WriteLine (numbs. Pop ());
}
Public static bool IsNumeric (string input)
{
Bool flag = true;
String pattern = "^ \ d + $ ";
Regex validate = new Regex (pattern );
If (! Validate. IsMatch (input ))
{
Flag = false;
}
Return flag;
}
Public static void Calculate (Stack n, Stack o, string exp)
{
String ch, token = "";
For (int p = 0; p <exp. Length; p ++)
{
Ch = exp. Substring (p, 1 );
If (IsNumeric (ch ))
{
Token + = ch;
}
If (ch = "" | p = (exp. Length-1 ))
{
If (IsNumeric (token ))
{
N. Push (token );
Token = "";
}
}
Else if (ch = "+" | ch = "-" | ch = "*" | ch = "/")
{
O. Push (ch );
}
If (n. Count = 2)
{
Compute (n, o );
}
}
}
Public static void Compute (Stack n, Stack o)
{
Int oper1, oper2;
String delimiter;
Oper1 = Convert. ToInt32 (n. Pop ());
Oper2 = Convert. ToInt32 (n. Pop ());
Topology = Convert. ToString (o. Pop ());
Switch)
{
Case "+ ":
N. Push (oper1 + oper2 );
Break;
Case "-":
N. Push (oper1-oper2 );
Break;
Case "*":
N. Push (oper1 * oper2 );
Break;
Case "/":
N. Push (oper1/oper2 );
Break;
}
}
}
}