Pagini recente » Cod sursa (job #2795431) | Cod sursa (job #2469652) | Cod sursa (job #506868) | Cod sursa (job #2194084) | Cod sursa (job #2974397)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("evaluare.in") ;
ofstream fout("evaluare.out") ;
char s[100001],*p,op[4][4] = {"+-", "*/", "^", ""};
int gata(int a,int b,char c)
{
if(c=='+') return a+b ;
if(c=='-') return a-b ;
if(c=='*') return a*b ;
if(c=='/') return a/b ;
}
int solve(int lvl)
{
int x,y ;
if(lvl==2)
{
if(*p=='(') p++,x=solve(0),p++ ;
else for(x=0; isdigit(*p); ++p) x=x*10+(*p-'0') ;
}
else
for(x=solve(lvl+1); strchr(op[lvl],*p); x=y) y=gata(x,solve(lvl+1),*p++) ;
return x ;
}
int main()
{
fin>>s ;
p=s ;
fout<<solve(0) ;
return 0;
}