Pagini recente » Cod sursa (job #1171614) | Cod sursa (job #2087918) | Monitorul de evaluare | Cod sursa (job #1239746) | Cod sursa (job #532400)
Cod sursa(job #532400)
#include <stdio.h>
#define DIM 100001
int expresie ();
int termeni ();
int factori ();
char S[DIM], *P = S;
int expresie ()
{
int n = termeni ();
while (*P == '+' || *P == '-')
if (*P == '+')
{
P++;
n += termeni ();
}
else
{
P++;
n -= termeni ();
}
return n;
}
int termeni ()
{
int n = factori ();
while (*P == '*' || *P == '/')
if (*P == '*')
{
P++;
n *= factori ();
}
else
{
P++;
n /= factori ();
}
return n;
}
int factori ()
{
int n = 0;
if (*P == '(')
{
P++;
n = expresie ();
P++;
}
else
while (*P >= '0' && *P <= '9')
{
n = n * 10 + *P - '0';
P++;
}
return n;
}
int main ()
{
freopen ("evaluare.in", "r", stdin);
freopen ("evaluare.out", "w", stdout);
fgets (S, DIM, stdin);
printf ("%d", expresie () );
return 0;
}