Pagini recente » Cod sursa (job #2508936) | Cod sursa (job #1212802) | Cod sursa (job #960762) | Cod sursa (job #2127836) | Cod sursa (job #2520741)
#include <bits/stdc++.h>
using namespace std;
#define MAX 100001
ifstream f("evaluare.in");
ofstream g("evaluare.out");
char s[MAX],*p=s;
long x;
long numar();
long fact();
long adsc()
{
long x=numar();
while(*p=='+' or *p=='-')
{
switch (*p)
{
case '+':
p++;
x=x+numar();
break;
case '-':
p++;
x=x-numar();
break;
}
}
return x;
}
long numar()
{
long x=fact();
while(*p=='*' or *p=='/')
{
{
switch (*p)
{
case '*':
p++;
x=x*fact();
break;
case '/':
p++;
x=x/fact();
break;
}
}
}
return x;
}
long fact()
{
x=0;
if(*p=='(')
{
p++;
x=adsc();
p++;
}
else
{
while(*p<='9' and *p>='0')
{
x=x*10+(*p-'0');
p++;
}
}
return x;
}
int main()
{
f.get(s,MAX);
g<<adsc();
}