Pagini recente » Cod sursa (job #2215706) | Cod sursa (job #1023318) | Cod sursa (job #2073659) | Cod sursa (job #2274081) | Cod sursa (job #3349960)
#include <bits/stdc++.h>
using namespace std;
#define USE_STD_IO 0
#if USE_STD_IO
#define fin cin
#define fout cout
#else
ifstream fin("evaluare.in");
ofstream fout("evaluare.out");
#endif // USE_STD_IO
char c[100002];
int n, i;
static inline int Numar();
static inline int ProdImp();
static inline int AddScad();
static inline int Numar() {
int nm = 0;
if('(' == c[i]) {
i++;
nm = AddScad();
i++;
}
else {
while(isdigit(c[i])) nm = nm * 10 + c[i++] - '0';
}
return nm;
}
static inline int ProdImp() {
int nm = Numar();
while('*' == c[i] || '/' == c[i]) {
char semn = c[i++];
if('*' == semn) nm *= Numar();
else nm /= Numar();
}
return nm;
}
static inline int AddScad() {
int nm = ProdImp();
while('+' == c[i] || '-' == c[i]) {
char semn = c[i++];
if('+' == semn) nm += ProdImp();
else nm -= ProdImp();
}
return nm;
}
int main() {
if(USE_STD_IO) ios_base::sync_with_stdio(false);
fin.tie(NULL);
fout.tie(NULL);
fin >> c;
n = strlen(c);
i = 0;
fout << AddScad();
return 0;
}