Pagini recente » Rating ili ili (ili123) | Cod sursa (job #534446) | Profil kovacskriszti | Statistici Alexandru Razvan-Andrei (WillingRazvan) | Cod sursa (job #1689564)
#include <fstream>
using namespace std;
ifstream f("evaluare.in");
ofstream g("evaluare.out");
char s[100005];
char* p;
int termen();
int factor();
int calc();
int factor()
{
int rez = 0;
if (*p == '(')
p++, rez = calc(), p++;
else if (*p >= '0' && *p <= '9')
{
while (*p >= '0' && *p <= '9')
rez = rez*10 + *p - '0', p++;
}
return rez;
}
int termen()
{
int rez = factor();
while (*p == '*' || *p == '/')
{
if (*p == '*')
p++, rez *= factor();
if (*p == '/')
p++, rez /= factor();
}
return rez;
}
int calc()
{
int rez = termen();
while (*p == '+' || *p == '-')
{
if (*p == '+')
p++, rez += termen();
else if (*p == '-')
p++, rez -= termen();
}
return rez;
}
int main()
{
f >> s;
p = s;
g << calc();
return 0;
}