Pagini recente » Cod sursa (job #1827625) | Cod sursa (job #3330523) | Cod sursa (job #2731235) | Cod sursa (job #2056420) | Cod sursa (job #1099726)
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <vector>
#include <bitset>
#include <string.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <deque>
using namespace std;
const char infile[] = "strmatch.in";
const char outfile[] = "strmatch.out";
const int MAXN = 100005;
const int oo = 0x3f3f3f3f;
typedef vector<int> Graph[MAXN];
typedef vector<int> :: iterator It;
const inline int min(const int &a, const int &b) { if( a > b ) return b; return a; }
const inline int max(const int &a, const int &b) { if( a < b ) return b; return a; }
const inline void Get_min(int &a, const int b) { if( a > b ) a = b; }
const inline void Get_max(int &a, const int b) { if( a < b ) a = b; }
char s[MAXN], *p = s;
int Termen ();
int Factor ();
int Eval () {
int r = Termen ();
while (*p == '+' || *p == '-') {
switch (*p) {
case '+': {
++p;
r += Termen ();
break;
}
case '-': {
++p;
r -= Termen ();
break;
}
}
}
return r;
}
int Termen () {
int r = Factor ();
while (*p == '*' || *p == '/') {
switch (*p) {
case '*': {
++p;
r *= Factor ();
break;
}
case '/': {
++p;
r /= Factor ();
break;
}
}
}
return r;
}
int Factor() {
int r = 0;
if (*p == '(') {
++p;
r = Eval ();
++p;
}
else
while (*p >= '0' && *p <= '9') {
r = r*10 + *p - '0';
++p;
}
return r;
}
int main () {
freopen ("evaluare.in", "r", stdin);
freopen ("evaluare.out", "w", stdout);
gets (s);
printf ("%d\n", Eval());
return 0;
}