Pagini recente » Cod sursa (job #2618165) | Cod sursa (job #1615416) | Cod sursa (job #2272982) | Cod sursa (job #494699) | Cod sursa (job #3209458)
#include <iostream>
#include <fstream>
#include <cctype>
#include <cstring>
using namespace std;
ifstream f("evaluare.in");
ofstream g("evaluare.out");
int n;
char *p, c[100005];
int eval();
int termen();
int factor();
int main()
{
f.get(c,100001);
p = c;
g << eval();
}
int eval(){
int rez = termen();
while(*p == '+' || *p == '-'){
if (*p == '+'){p++;rez += termen();}
else {p++;rez -= termen();}
}
return rez;
}
int termen(){
int rez = factor();
while(*p == '*' || *p == '/'){
if (*p == '*'){p++;rez *= factor();}
if (*p == '/'){p++;rez /= factor();}
}
return rez;
}
int factor(){
int rez = 0;
if (*p == '('){p++;rez = eval();p++;}
while(*p >= '0' && *p <= '9'){rez = rez * 10 + (int)*p - '0';p++;}
return rez;
}