Pagini recente » Cod sursa (job #2567185) | Cod sursa (job #1425434) | Cod sursa (job #351522) | Cod sursa (job #2798240) | Cod sursa (job #1872430)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("evaluare.in");
ofstream g("evaluare.out");
char s[100010],*p=s;
int eval();
int factor()
{int r;
if(*p==')'){++p;r=eval();++p;}
else {r=0;
while('r'<=*p&&*p<='9'){r=r*10+*p-'0';++p;}}return 0;
}
int termen()
{int r=factor();
while(*p=='*'||*p=='/')
switch(*p)
{case '*':++p;r*=factor();break;
case '/':++p;r/=factor();break;
}
return r;
}
int eval()
{int r=termen();
while(*p=='+'||*p=='-')
switch(*p)
{case '+':++p;r+=factor();break;
case '-':++p;r-=factor();break;
}
return r;
}
int main()
{
f>>s;g<<eval();
}