Pagini recente » Cod sursa (job #3032617) | Cod sursa (job #125060) | Cod sursa (job #2459851) | Cod sursa (job #1514423) | Cod sursa (job #2507044)
#include <bits/stdc++.h>
using namespace std;
ifstream f ("evaluare.in");
ofstream g ("evaluare.out");
char a[100005];
char *p = a;
int Eval();
int Termen();
int Factor();
int Eval()
{
int r = Termen();
while(*p == '+' || *p == '-')
{
if(*p == '+')
{
++p;
r += Termen();
}
else
{
++p;
r -= Termen();
}
}
return r;
}
int Termen()
{
int r = Factor();
while(*p == '*' || *p == '/')
{
if(*p == '*')
{
++p;
r *= Factor();
}
else
{
++p;
r /= Factor();
}
}
return r;
}
int Factor()
{
int r = 0;
if(*p == '(')
{
++p;
r = Eval();
++p;
}
else while(isdigit(*p))
r = r * 10 + *p - '0' , p++;
return r;
}
int main()
{
f >> a;
g << Eval();
return 0;
}