62,046
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string str = "a * (b - c)";
string str1 = "2*(10-9.5)";
string str2 = Compute(str1);
Console.WriteLine(str);
Console.WriteLine(str1);
Console.WriteLine(str2);
Console.ReadLine();
}
static string Compute(string str)
{
string a = str.Substring(0,str.IndexOf('*'));
string b = str.Substring(str.IndexOf('(')+1,str.IndexOf('-')-str.IndexOf('(')-1);
string c = str.Substring(str.IndexOf('-')+1, str.IndexOf(')') - str.IndexOf('-') - 1);
double temp = Convert.ToDouble(a) * (Convert.ToDouble(b) - Convert.ToDouble(c));;
return Convert.ToString(temp);
}
}