Pagini recente » Cod sursa (job #2343594) | Cod sursa (job #3270830) | Cod sursa (job #2771518) | Cod sursa (job #892405) | Cod sursa (job #3278860)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("evaluare.in");
ofstream fout("evaluare.out");
const int NMAX = 100000;
char s[NMAX+1], *p;
long long nr(); long long eval(); long long chunk();
long long nr()
{
int x = 0;
if(*p == '(')
{p++; x = eval(); p++;}
else
{
while(isdigit(*p))
x = x*10 + (*p-'0'), p++;
}
return x;
}
long long chunk()
{
int x = nr();
while(*p == '*' || *p == '/')
{
if(*p == '*')
p++, x*=nr();
else if(*p == '/')
p++, x/=nr();
}
return x;
}
long long eval()
{
int x = chunk() ;
while(*p == '+' || *p == '-')
{
if(*p == '+')
p++, x+=chunk();
else if(*p == '-')
p++, x-=chunk();
}
return x;
}
int main()
{
fin >> s;
p = s;
fout << eval();
return 0;
}