Pagini recente » Cod sursa (job #1913610) | Cod sursa (job #727980) | Cod sursa (job #2457727) | Cod sursa (job #2462805) | Cod sursa (job #1376293)
#include<cstdio>
#include<fstream>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<bitset>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<cmath>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<unordered_map>
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
const int nmax = 100005;
int e(), t(), f();
char s[nmax], *p;
int main()
{
freopen("evaluare.in", "r", stdin);
freopen("evaluare.out", "w", stdout);
scanf("%s", s);
p = s;
printf("%d\n", e());
return 0;
}
int e()
{
int r = t();
while(*p == '+' || *p == '-')
{
if(*p == '+') p++, r += t();
else p++, r -= t();
}
return r;
}
int t()
{
int r = f();
while(*p == '*' || *p == '/')
{
if(*p == '*') p++, r *= f();
else p++, r /= f();
}
return r;
}
int f()
{
int r = 0;
if(*p == '(')
{
p++;
r = e();
p++;
return r;
}
while(*p >= '0' && *p <= '9')
r = r * 10 + *p - '0', p++;
return r;
}