All pastes #424416 Raw Edit

Shadow

public cpp v1 · immutable
·published 2007-04-04 19:42 UTC
rendered paste body
#include <iostream>#include <string>#include <sstream>#include <algorithm> using namespace std; template <typename Iterator> void F1(string & str, Iterator begin, Iterator end){         Iterator i, temp, i1;         int count = 0;         float f;         for ( ;; ) {              for (i = str.begin ();i != str.end ();++i) {                  if (*i == '(') {                        ++count;                        temp = i;                 }                 else if (*i == ')') {                      ++count;                      f=F(temp,i+1);                      ostringstream ss;                      ss << f ;                      string s = ss.str();                      str.replace (temp,i+1,s) ;                 }             }             if (count == 0) return;          }} template <typename Iterator> 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);    F1(str,str.begin(),str.end());    a = F(str.begin(),str.end());    cout << "Ats: " << a << endl;    cin.get();}