Pagini recente » Cod sursa (job #2118794) | Cod sursa (job #1163499) | Cod sursa (job #3192660) | Cod sursa (job #3289116) | Cod sursa (job #2876815)
#include <fstream>
#include <queue>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
#define Inf 0x3f3f3f3f
ifstream cin("evaluare.in");
ofstream cout("evaluare.out");
string a;
int p = 0;
int rez;
int termen();
int eval();
int factor();
int eval(){
int ans = termen();
while(a[p] == '+'){
p++;
ans += termen();
}
while(a[p] == '-'){
p++;
ans -= termen();
}
return ans;
}
int termen(){
int ans = factor();
if(a[p] == '*'){
p++;
ans *= factor();
}
else if(a[p] == '/'){
p++;
ans /= factor();
}
return ans;
}
int factor(){
int ans = 0;
if(a[p] == '('){
p++;
ans = eval();
p++;
}
else{
while(a[p] >= '0' && a[p] <= '9')
ans = ans * 10 + (a[p++] - '0');
}
return ans;
}
int main(){
cin >> a;
cout << eval();
return 0;
}