using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Computer
{
public class Compute
{
public double Number1
{
get;
set;
}
public string Operater
{
get;
set;
}
public double Number2
{
get;
set;
}
public Compute(double number1, string operater, double number2)
{
this.Number1 = number1;
this.Operater = operater;
this.Number2 = number2;
}
public double GetResult()
{
switch (Operater)
{
case "+":
return Number1 + Number2;
case "-":
return Number1 - Number2;
case "*":
return Number1 * Number2;
case "/":
return Number1 / Number2;
default: return 0;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Computer
{
class Program
{
static void Main(string[] args)
{
List<string> list = new List<string>();
string str = Console.ReadLine();
int index = -1;
for (int i = 0; i < str.Length; i++)
{
if (str[i]=='+'||str[i]=='-'||str[i]=='*'||str[i]=='/'||str[i]=='=')
{
list.Add(str.Substring(index+1,i-index-1).Trim());
list.Add(str[i].ToString());
index = i;
}
}
while (true)
{
if (!list.Contains("*") && !list.Contains("/"))
{
break;
}
else
{
int i = -1;
if (list.IndexOf("*")>-1)
{
i = list.IndexOf("*");
}
if (i!=-1)
{
if (list.IndexOf("/") > -1 && i > list.IndexOf("/"))
{
i = list.IndexOf("/");
}
}
else
{
if (list.IndexOf("/")>-1)
{
i = list.IndexOf("/");
}
}
if (i != -1)
{
Compute c = new Compute(double.Parse(list[i - 1]), list[i], double.Parse(list[i + 1]));
list.RemoveAt(i - 1);
list.RemoveAt(i - 1);
list.RemoveAt(i - 1);
list.Insert(i - 1, c.GetResult().ToString());
}
}
}
while (list.Count > 2)
{
Compute c = new Compute(double.Parse(list[0]), list[1], double.Parse(list[2]));
list.RemoveAt(0);
list.RemoveAt(0);
list.RemoveAt(0);
list.Insert(0,c.GetResult().ToString());
}
Console.WriteLine(str+list[0]);
Console.ReadLine();
}
}
}
浙公网安备 33010602011771号