Pagini recente » Cod sursa (job #2948081) | Cod sursa (job #2535013) | Cod sursa (job #2670377) | Cod sursa (job #2768362) | Cod sursa (job #1131042)
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
ifstream fin("evaluare.in");
ofstream fout("evaluare.out");
int n, p = 1;
char a[100005];
int g1(), g2(), g3();
int g1() {
int t = g2();
while (a[p] == '+' || a[p] == '-') {
++p;
if (a[p - 1] == '+')
t += g2();
else
t -= g2();
}
return t;
}
int g2() {
int t = g3();
while (a[p] == '*' || a[p] == '/') {
++p;
if (a[p - 1] == '*')
t *= g3();
else
t /= g3();
}
return t;
}
int g3() {
int t = 0;
if (a[p] == '(') {
++p;
t = g1();
++p;
} else {
while ('0' <= a[p] && a[p] <= '9') {
t = t * 10 + a[p] - '0';
++p;
}
}
return t;
}
int main() {
fin.getline(a + 1, 100002);
fout << g1();
fin.close();
fout.close();
}