Pagini recente » Cod sursa (job #999058) | Cod sursa (job #1288427) | Cod sursa (job #1566862) | Cod sursa (job #1888650) | Cod sursa (job #339218)
Cod sursa(job #339218)
#include<cstdio>
const int N = (1<<17);
char s[N],*p;
int expresie();
int termen();
int factor();
int factor()
{
int x=0;
if(*p=='(')
{
++p;
x=expresie();
++p;
}
while(*p>='0' && *p<='9')
x=x*10+(*p++)-'0';
return x;
}
int termen()
{
int x=factor();
while(*p=='*' || *p=='/')
x=(*p++=='*' ? x*factor() : x/factor());
return x;
}
int expresie()
{
int x=termen();
while(*p=='+' || *p=='-')
x+=(*p++=='+' ? termen() : -termen());
return x;
}
int main()
{
freopen("evaluare.in","r",stdin);
freopen("evaluare.out","w",stdout);
fgets(s,N,stdin);
p=s;
printf("%d\n",expresie());
return 0;
}