Pagini recente » Cod sursa (job #2946508) | Cod sursa (job #2842404) | Cod sursa (job #1144034) | Cod sursa (job #2726358) | Cod sursa (job #145231)
Cod sursa(job #145231)
#include <stdio.h>
char s[100111];
int poz;
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\n",eval());
return 0;
}