Pagini recente » Cod sursa (job #873754) | Cod sursa (job #885406) | Cod sursa (job #134175) | Cod sursa (job #406029) | Cod sursa (job #1359448)
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fs first
#define sc second
#define pob pop_back
#define pub push_back
#define eps 1E-7
#define sz(a) a.size()
#define count_one __builtin_popcount;
#define count_onell __builtin_popcountll;
#define fastIO ios_base::sync_with_stdio(false)
#define PI (acos(-1.0))
#define linf (1LL<<62)//>4e18
#define inf (0x7f7f7f7f)//>2e9
#define DEBUG 1
#ifdef DEBUG
#define D(x) x
#else
#define D(x)
#endif
char in[100000], *p;
ifstream f("evaluare.in");
ofstream g("evaluare.out");
char pr[4][4] = { "+-", "*/", "", "" };
int eval(int a, int b, int op) {
switch(op) {
case '+': return a + b;
case '-': return a - b;
case '*': return a * b;
case '/': return a / b;
}
}
int solve(int prior) {
int x, y;
if( prior == 2 )
if(*p == '(') {
p++; x = solve(0), p++;
} else
for(x = 0; isdigit(*p); p++) {
x = x * 10 + *p - '0';
}
else
for(x = solve(prior + 1); strchr(pr[prior], *p); x = y)
y = eval(x, solve(prior+1), *p++);
return x;
}
int main() {
f >> in;
p = in;
g << solve(0);
return 0;
}