#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<cstring>
#include <sstream>
using namespace std;
void part(string str, vector<double> &_num, vector<char> &_op);
double stringToNum(string str);
double sz(string str);
double out(string str);
//拆括号
double out(string str)
{
for (int i = 0; i < (int)str.size(); i ++)
{
if ('-' == str[i])
replace(str.begin()+i,str.end(),'-','_');
}
int num = 0;
size_t fi = str.find('(', 0);
while (fi!=str.npos)
{
int nCount1 = str.find('(');
int nCount2 = str.find(')');
str = str.substr(0,nCount1) + std::to_string(sz(str.substr(nCount1+1,nCount2-nCount1-1))) + str.substr(nCount2+1,str.size()+1);
num++;
fi = str.find('(', fi + 1);
}
return sz(str);
if (0 == num)
return sz(str);
}
//模板函数:将string类型变量转换为常用的数值类型(此方法具有普遍适用性)
double stringToNum(string str)
{
istringstream iss(str);
double num;
iss >> num;
return num;
}
//将输入的字符串拆成两部分
void part(string str, vector<double> &num, vector<char> &op)
{
double sum = 0;
double lastsum = 0;
unsigned int i = 0;
while( i < str.length())
{
if (str[i] == '+' || str[i]== '_' || str[i] == '*' || str[i]== '/'|| str[i]== '^')
{
op.push_back(str[i]);
sum = stringToNum(str.substr(0,i));
num.push_back(sum);
sum = 0;
str = str.erase(0,i+1);
i = 0;
}
else
{
i=i+1;
}
}
lastsum = stringToNum(str);
num.push_back(lastsum);
}
//运算
double sz(string str)
{
vector<double> num(0);
vector<char> op(0);
part(str, num, op);
char str1[50]="+";
for ( unsigned j = 0; j < op.size(); j++)
{
if (op[j] == '^')
{
num[j+1] = pow(num[j],num[j+1]);
num[j] = 0;
j < 1? op[j] = str1[50]: op[j] = op[j-1];
}
}
for ( unsigned j = 0; j < op.size(); j++)
{
if (op[j] == '*')
{
num[j+1] = (num[j])*(num[j+1]);
num[j] = 0;
j < 1? op[j] = str1[50]: op[j] = op[j-1];
}
if (op[j] == '/')
{
num[j+1] = (num[j])/(num[j+1]);
num[j] = 0;
j < 1?op[j] = str1[50]:op[j] = op[j-1];
}
}
for ( unsigned j = 0; j < op.size(); j++)
{
if (op[j] == '+')
num[j+1] = (num[j])+(num[j+1]);
if (op[j] == '_')
num[j+1] = (num[j])-(num[j+1]);
}
return num[op.size()];
}
//主函数
int main()
{
string str;
while(cin>>str)
{
typedef numeric_limits< double > num;
cout.precision(num::digits10);
cout<< out(str) << endl;
}
return 0;
}
#include <string>
#include <vector>
#include <algorithm>
#include<cstring>
#include <sstream>
using namespace std;
void part(string str, vector<double> &_num, vector<char> &_op);
double stringToNum(string str);
double sz(string str);
double out(string str);
//拆括号
double out(string str)
{
for (int i = 0; i < (int)str.size(); i ++)
{
if ('-' == str[i])
replace(str.begin()+i,str.end(),'-','_');
}
int num = 0;
size_t fi = str.find('(', 0);
while (fi!=str.npos)
{
int nCount1 = str.find('(');
int nCount2 = str.find(')');
str = str.substr(0,nCount1) + std::to_string(sz(str.substr(nCount1+1,nCount2-nCount1-1))) + str.substr(nCount2+1,str.size()+1);
num++;
fi = str.find('(', fi + 1);
}
return sz(str);
if (0 == num)
return sz(str);
}
//模板函数:将string类型变量转换为常用的数值类型(此方法具有普遍适用性)
double stringToNum(string str)
{
istringstream iss(str);
double num;
iss >> num;
return num;
}
//将输入的字符串拆成两部分
void part(string str, vector<double> &num, vector<char> &op)
{
double sum = 0;
double lastsum = 0;
unsigned int i = 0;
while( i < str.length())
{
if (str[i] == '+' || str[i]== '_' || str[i] == '*' || str[i]== '/'|| str[i]== '^')
{
op.push_back(str[i]);
sum = stringToNum(str.substr(0,i));
num.push_back(sum);
sum = 0;
str = str.erase(0,i+1);
i = 0;
}
else
{
i=i+1;
}
}
lastsum = stringToNum(str);
num.push_back(lastsum);
}
//运算
double sz(string str)
{
vector<double> num(0);
vector<char> op(0);
part(str, num, op);
char str1[50]="+";
for ( unsigned j = 0; j < op.size(); j++)
{
if (op[j] == '^')
{
num[j+1] = pow(num[j],num[j+1]);
num[j] = 0;
j < 1? op[j] = str1[50]: op[j] = op[j-1];
}
}
for ( unsigned j = 0; j < op.size(); j++)
{
if (op[j] == '*')
{
num[j+1] = (num[j])*(num[j+1]);
num[j] = 0;
j < 1? op[j] = str1[50]: op[j] = op[j-1];
}
if (op[j] == '/')
{
num[j+1] = (num[j])/(num[j+1]);
num[j] = 0;
j < 1?op[j] = str1[50]:op[j] = op[j-1];
}
}
for ( unsigned j = 0; j < op.size(); j++)
{
if (op[j] == '+')
num[j+1] = (num[j])+(num[j+1]);
if (op[j] == '_')
num[j+1] = (num[j])-(num[j+1]);
}
return num[op.size()];
}
//主函数
int main()
{
string str;
while(cin>>str)
{
typedef numeric_limits< double > num;
cout.precision(num::digits10);
cout<< out(str) << endl;
}
return 0;
}