Pagini recente » Cod sursa (job #434420) | Cod sursa (job #2376937) | Cod sursa (job #2273229) | Cod sursa (job #262583) | Cod sursa (job #1290047)
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define dbg(x) (cout<<#x<<" = "<<(x)<<'\n')
#ifdef HOME
const string inputFile = "input.txt";
const string outputFile = "output.txt";
#else
const string problemName = "evaluare";
const string inputFile = problemName + ".in";
const string outputFile = problemName + ".out";
#endif // HOME
typedef long long int lld;
typedef pair<int, int> PII;
typedef pair<int, lld> PIL;
typedef pair<lld, int> PLI;
typedef pair<lld, lld> PLL;
const int INF = (1LL << 31) - 1;
const lld LINF = (1LL << 62) - 1;
const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int MOD = (int)(1e9) + 7;
const int NMAX = 100000 + 5;
const int MMAX = 100000 + 5;
const int KMAX = 100000 + 5;
const int PMAX = 100000 + 5;
const int LMAX = 100000 + 5;
const int VMAX = 100000 + 5;
char sir[NMAX], *p;
int eval(), term(), fact(), numb();
int eval() {
int a = term();
while(*p == '+' || *p == '-')
if(*p == '+') {
p++;
a += term();
} else if(*p == '-') {
p++;
a -= term();
}
return a;
}
int term() {
int a = fact();
while(*p == '*' || *p == '/')
if(*p == '*') {
p++;
a *= fact();
} else if(*p == '/') {
p++;
a /= fact();
}
return a;
}
int fact() {
if(*p == '(') {
p++;
int a = eval();
p++;
return a;
} else
return numb();
}
int numb() {
int a = 0, semn = 1;
if(*p == '-') {
semn = -1;
p++;
}
while('0' <= *p && *p <= '9') {
a = a * 10 + *p - '0';
p++;
}
return a * semn;
}
int main() {
#ifndef ONLINE_JUDGE
freopen(inputFile.c_str(), "r", stdin);
freopen(outputFile.c_str(), "w", stdout);
#endif
scanf("%s", sir);
p = sir;
printf("%d\n", eval());
return 0;
}