Pagini recente » Cod sursa (job #2476435) | Cod sursa (job #1656991) | Cod sursa (job #2829795) | Cod sursa (job #2798565) | Cod sursa (job #3255381)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("evaluare.in");
ofstream cout("evaluare.out");
int t;
char v[100010];
int trm();
int f();
int exp() {
int aux=trm();
while(v[t]=='+'||v[t]=='-') {
if(v[t]=='+'){
t++;
aux+=trm();
}
else {
t++;
aux-=trm();
}
}
return aux;
}
int trm() {
int aux=f();
while(v[t]=='/'||v[t]=='*') {
if(v[t]=='/'){
t++;
aux/=f();
}
else {
t++;
aux*=f();
}
}
return aux;
}
int f() {
int aux=0;
if(v[t]=='(') {
t++;
aux=exp();
t++;
}
else {
aux=0;
while(v[t]>='0'&&v[t]<='9') {
aux*=10;
aux+=v[t]-'0';
t++;
}
}
return aux;
}
int main() {
cin>>v;
t=0;
cout<<exp();
}