#include #include #include #include using namespace std; template void F1(string & str, Iterator begin, Iterator end) { float f; Iterator i = begin, begin1,i1; int count=0; while(i!=end) { if(*i == '(') {++count; begin1 = i; ++i; } else if (*i == ')') { --count; if(count == 0) { F1(str,begin1+1, i-1); } else ++i; } else { f=F(begin,end); ostringstream ss; ss << f ; string s = ss.str(); i1=str.erase(begin,end); str.insert(i1,s.begin(),s.end()); F1(str,str.begin(),str.end()); } } } template float F(Iterator begin, Iterator end) { Iterator i; if ((i = find(begin,end,'+')) != end) { return F(begin,i) + F(i+1,end) ; }else if ((i = find(begin,end,'-')) != end) { return F(begin,i) - F(i+1,end) ; }else if ((i = find(begin,end,'*')) != end) { return F(begin,i) * F(i+1,end) ; }else if ((i = find(begin,end,'/')) != end) { return F(begin,i) / F(i+1,end) ; }else { string str1(begin,end) ; istringstream stream(str1); float i; stream >> i; return i ; } } int main() { string str,str1; float a; getline(cin,str); str = F1(str,str.begin(),str.end()); //a = F(str.begin(),str.end()); cout << "Ats: " << a << endl; cin.get(); }