Pagini recente » Cod sursa (job #2161625) | Cod sursa (job #827448) | Cod sursa (job #1822943) | Cod sursa (job #427967) | Cod sursa (job #2862215)
#include <fstream>
#include<cstring>
#include<algorithm>
using namespace std;
ifstream fin("evaluare.in");
ofstream fout("evaluare.out");
char s[100002];
int index;
long long expresie();
long long produs();
long long suma();
long long expresie()
{
if(isdigit(s[index]))
{
long long nr = 0;
while(isdigit(s[index]))
{
nr = nr * 10 + (s[index] - '0');
index++;
}
return nr;
}
else if(s[index] == '(')
{
index++;
//o iau de la capat
long long x = suma();
index++;
return x;
}
}
long long produs()
{
int temp = expresie();
while(s[index] == '*' || s[index] == '/')
{
if(s[index] == '*')
{
index++;
temp *= expresie();
}
else if(s[index] == '/')
{
index++;
temp /= expresie();
}
}
return temp;
}
long long suma()
{
int temp = produs();
while(s[index] == '+' || s[index] == '-')
{
if(s[index] == '+')
{
index++;
temp += produs();
}
else if(s[index] == '-')
{
index++;
temp -= produs();
}
}
return temp;
}
int main()
{
int n,i,j,k;
fin.getline(s, 100002);
fout<<suma();
return 0;
}