Pagini recente » Cod sursa (job #1345935) | Cod sursa (job #2599612) | Cod sursa (job #2313771) | Cod sursa (job #1207408) | Cod sursa (job #952106)
Cod sursa(job #952106)
#include<cstdio>
using namespace std;
const int NMAX = 100005;
char S[NMAX],*p;
int E(),T(),F();
int main()
{
freopen("evaluare.in","r",stdin);
freopen("evaluare.out","w",stdout);
scanf("%s",S); p=S;
printf("%d\n",E());
return 0;
}
int E()
{
int rez=T();
while(*p=='+' || *p=='-')
{
if(*p=='+') p++,rez+=T();
else p++,rez-=T();
}
return rez;
}
int T()
{
int rez=F();
while(*p=='*' || *p=='/')
{
if(*p=='*') p++,rez*=T();
else p++,rez/=T();
}
return rez;
}
int F()
{
int rez=0;
if(*p=='(') {p++;rez=E();p++;return rez;}
while(*p>='0' && *p<='9') rez=rez*10+*p-'0',p++;
return rez;
}