Pagini recente » Cod sursa (job #826519) | Cod sursa (job #25934) | Cod sursa (job #2897778) | Istoria paginii runda/simulareinfo_oji_7_9/clasament | Cod sursa (job #2682825)
#include <bits/stdc++.h>
using namespace std;
ifstream f("evaluare.in");
ofstream g("evaluare.out");
char s[100005], *p;
int termen();
int factor();
int ecuatie();
int termen()
{
int rez = factor();
while(*p == '*' || *p == '/')
{
if(*p == '*')
p++, rez *= factor();
else
p++, rez /= factor();
}
return rez;
}
int factor()
{
int rez=0;
if(*p == '(')
p++, rez = ecuatie(),p++;
else
{
while(isdigit(*p))
{
rez = rez * 10 + *p - '0';
p++;
}
}
return rez;
}
int ecuatie()
{
int rez = termen();
while(*p == '+' || *p == '-')
{
if(*p=='+')
p++, rez += termen();
else
p++, rez -= termen();
}
return rez;
}
int main()
{
f >> s;
p = s;
g << ecuatie();
}