Pagini recente » Profil Andrew07 | Cod sursa (job #874788) | Cod sursa (job #2349087) | Cod sursa (job #2677541) | Cod sursa (job #2355735)
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
char *s;
int eval();
int term();
int get();
int eval() {
int t = term();
while(*s == '+' || *s == '-') {
if(*s == '+')
s++, t += term();
else
s++, t -= term();
}
return t;
}
int term() {
int t = get();
while(*s == '*' || *s == '/') {
if(*s == '*')
s++, t *= get();
else
s++, t /= get();
}
return t;
}
int get() {
int t;
if(*s == '(') {
s++;
t = eval();
s++;
}
else {
int semn = 1;
if(*s == '-')
semn = -1, s++;
t = 0;
while(isdigit(*s))
t = t * 10 + *s - '0', s++;
t *= semn;
}
return t;
}
int main() {
ifstream cin("evaluare.in");
ofstream cout("evaluare.out");
s = new char[maxn];
cin >> s;
cout << eval();
return 0;
}