Pagini recente » Cod sursa (job #2288430) | Borderou de evaluare (job #2274604) | Cod sursa (job #426113)
Cod sursa(job #426113)
#include<cstdio>
int poz;
char s[100111];
int eval();
int term();
int fact()
{
int aux=0;
if(s[poz]=='(')
{
poz++;
aux=eval();
poz++;
return aux;
}
while(s[poz]>='0'&&s[poz]<='9')
aux=aux*10+s[poz++]-'0';
return aux;
}
int term()
{
int aux=fact();
while(s[poz]=='*'||s[poz]=='/')
if(s[poz++]=='*')
aux*=fact();
else
aux/=fact();
return aux;
}
int eval()
{
int aux=term();
while(s[poz]=='+'||s[poz]=='-')
if(s[poz++]=='+')
aux+=term();
else
aux-=term();
return aux;
}
int main()
{
freopen("evaluare.in","r",stdin);
freopen("evaluare.out","w",stdout);
scanf("%s",&s);
printf("%d",eval());
return 0;
}