All pastes #424106 Raw Edit

Shadow

public cpp v1 · immutable
·published 2007-04-04 16:07 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){         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 <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);    str = F1(str,str.begin(),str.end());    //a = F(str.begin(),str.end());    cout << "Ats: " << a << endl;    cin.get();}