Pagini recente » Cod sursa (job #2145709) | Cod sursa (job #1611000) | Cod sursa (job #1328980) | Cod sursa (job #2192094) | Cod sursa (job #2290634)
#include <bits/stdc++.h>
using namespace std;
ifstream f("evaluare.in");
ofstream g("evaluare.out");
char E[100010],*p;
int sum(),prod(),fact(),num();
int main()
{
p=E;
f>>p;
g<<sum();
return 0;
}
int sum()
{
int rez=prod();
while(*p=='+'||*p=='-')
{
if(*p=='+'){p++;rez+=prod();}
else {p++;rez-=prod();}
}
return rez;
}
int prod()
{
int rez=fact();
while(*p=='*'||*p=='/')
{
if(*p=='*'){p++;rez*=fact();}
else {p++;rez/=fact();}
}
return rez;
}
int fact()
{
if(*p=='(')
{
p++;
int rez=sum();
p++;
return rez;
}
return num();
}
int num()
{
int rez=0;
while(isdigit(*p)){rez=10*rez+*p-'0';p++;}
return rez;
}