Pagini recente » Cod sursa (job #3273734) | Cod sursa (job #2553276) | Cod sursa (job #3144721) | Cod sursa (job #1184194) | Cod sursa (job #145236)
Cod sursa(job #145236)
#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;
}