Pagini recente » Cod sursa (job #2078978) | Istoria paginii runda/abac | Cod sursa (job #596583) | Cod sursa (job #1244057) | Cod sursa (job #1921609)
#include <bits/stdc++.h>
using namespace std;
int where;
char s[100009];
int functie3();
int functie2();
int functie1 ()
{
int raspuns = functie2();
while (s[where] == '+' || s[where] == '-')
{
if (s[where] == '+')
{
++where;
raspuns += functie2();
}
else
{
++where;
raspuns -= functie2();
}
}
return raspuns;
}
int functie2 ()
{
int raspuns = functie3();
while (s[where] == '*' || s[where] == '/')
{
if (s[where] == '*')
{
++where;
raspuns *= functie3();
}
else
{
++where;
raspuns /= functie3();
}
}
return raspuns;
}
int functie3 ()
{
int raspuns = 0;
if (s[where] == '(')
{
++where;
raspuns = functie1();
++where;
}
else
{
while (s[where]>='0' && s[where]<='9')
{
raspuns = raspuns*10+(s[where]-'0');
++where;
}
}
return raspuns;
}
int main()
{
ifstream fin ("evaluare.in");
ofstream fout ("evaluare.out");
fin.getline(s, 100009);
fout << functie1();
return 0;
}