Pagini recente » Cod sursa (job #2689189) | Cod sursa (job #2136472) | Cod sursa (job #2534747) | Cod sursa (job #1522785) | Cod sursa (job #567557)
Cod sursa(job #567557)
#include <stdio.h>
#include <string.h>
using namespace std;
char a[100100];
int n;
int i;
int ord1();
int ord2();
int eval();
int ord1()
{
int rez=ord2();
while(a[i]=='+' || a[i]=='-')
{
if(a[i]=='+')
{
i++;
rez+=ord2();
}
if(a[i]=='-')
{
i++;
rez-=ord2();
}
}
return rez;
}
int ord2()
{
int rez=eval();
while(a[i]=='*' || a[i]=='/')
{
if(a[i]=='*')
{
i++;
rez*=eval();
}
if(a[i]=='/')
{
i++;
rez/=eval();
}
}
return rez;
}
int eval()
{
int rez=0;
if(a[i]=='(' )
{
i++;
rez=ord1();
i++;
}
else
{
sscanf(a+i,"%d",&rez);
for(;a[i]>='0' && a[i]<='9';++i);
}
return rez;
}
int main()
{
freopen("evaluare.in","r",stdin);
freopen("evaluare.out","w",stdout);
gets(a);
n=strlen(a);
printf("%d",ord1());
return 0;
}