Pagini recente » Cod sursa (job #1309930) | Cod sursa (job #1055133) | Cod sursa (job #1625480) | Cod sursa (job #2693843) | Cod sursa (job #1754739)
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
ifstream fin("evaluare.in");
ofstream fout("evaluare.out");
char exp[100100], *p = exp, op[2][4] = {"+-", "*/"};
//int grad = 0;
void citire()
{
fin>>exp;
}
int operatie(int a, int b, char c)
{
if(c == '+') return a + b;
if(c == '-') return a - b;
if(c == '*') return a * b;
if(c == '/') return a / b;
}
int expresie(int grad)
{
int x = 0, y;
if(grad > 1)
{
if(*p >= '0' && *p <= '9')
{
while(*p >= '0' && *p <= '9')
{
x = x * 10 + (*p - '0');
++p;
}
return x;
}
else
{
p++;
x = expresie(0);
p++;
}
}
else
{
x = expresie(grad + 1);
while(grad == 0 && (*p == '+' || *p == '-') || (*p == '*' || *p == '/'))
{
p++;
y = operatie(x, expresie(grad + 1), *(p - 1));
x = y;
}
}
return x;
}
int main()
{
citire();
fout<<expresie(0);
return 0;
}