Pagini recente » Cod sursa (job #3270506) | Cod sursa (job #600617) | Monitorul de evaluare | Cod sursa (job #249026) | Cod sursa (job #2252929)
#include <bits/stdc++.h>
using namespace std;
char str[100005], *s;
int getint();
int fact();
int eval();
int getint()
{
if(*s == '(')
{
s++;
int nr = eval();
s++;
return nr;
}
int nr = 0;
while(isdigit(*s))
{
nr = nr * 10 + *s - '0';
s++;
}
return nr;
}
int fact()
{
int nr = getint();
while(*s == '*' || *s == '/')
{
if(*s == '*')
{
s++;
int b = getint();
nr *= b;
}
else
{
s++;
int b = getint();
nr /= b;
}
}
return nr;
}
int eval()
{
int nr = fact();
while(*s == '+' || *s == '-')
{
if(*s == '+')
{
s++;
int b = fact();
nr += b;
}
else
{
s++;
int b = fact();
nr -= b;
}
}
return nr;
}
int main()
{
freopen("evaluare.in", "r", stdin);
freopen("evaluare.out", "w", stdout);
scanf("%s", str);
s = str;
printf("%d", eval());
return 0;
}