Pagini recente » Cod sursa (job #1695003) | Cod sursa (job #3276892) | Cod sursa (job #2553538) | Cod sursa (job #2430617) | Cod sursa (job #3225440)
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
#define pb push_back
ifstream fin("evaluare.in");
ofstream fout("evaluare.out");
int p;
string s;
int factor(), termen(), suma();
int main()
{
fin.tie(0); fout.tie(0);
ios_base::sync_with_stdio(0);
fin >> s;
fout << suma();
return 0;
}
int factor(){
int ret = 0;
if (s[p] == '('){
p++; ret = suma(); p++;
return ret;
}
for (; isnumber(s[p]); p++) ret = ret * 10 + s[p] - '0';
return ret;
}
int termen(){
int ret = factor();
if (s[p] == '*') { p++; ret *= termen(); }
else if (s[p] == '/') { p++; ret /= termen(); }
return ret;
}
int suma(){
int ret = termen();
if (s[p] == '+') { p++; ret += termen(); }
else if (s[p] == '-') { p++; ret -= termen(); }
return ret;
return 0;
}
//16:44