Cod sursa(job #765333)
#include<cstdio>
#include<cstdlib>
#define N 100001
char *s;
int E(char *&p)
{int T(char*&);
char c;
int w,r=T(p);
if(!(*p))
return r;
while((c=*p)=='+'||c=='-')
{w=T(++p);
if(c=='+')
r+=w;
else
r-=w;}
return r;}
int T(char *&p)
{int F(char*&);
char c;
int w,r=F(p);
if(!(*p))
return r;
while((c=*p)=='*'||c=='/')
{w=F(++p);
if(c=='*')
r*=w;
else
r/=w;}
return r;}
int F(char *&p)
{int r;
if(*p=='(')
{r=E(++p),p++;
return r;}
else
return (int)strtod(p,&p);}
int main()
{freopen("evaluare.in","r",stdin);
freopen("evaluare.out","w",stdout);
s=new char[N];
gets(s);
printf("%d",E(s));
return 0;}