Pagini recente » Cod sursa (job #716302) | Cod sursa (job #2362974) | Monitorul de evaluare | Cod sursa (job #2187617) | Cod sursa (job #1921937)
#include <bits/stdc++.h>
#define impartire 1000000001
#define inmultire 1000000002
#define scadere 1000000003
#define paranteza 1000000004
using namespace std;
ifstream fin("evaluare.in");
ofstream fout("evaluare.out");
char s[100005];
int st[100005],top;
void Citire()
{
fin>>s;
fin.close();
}
void Rez()
{
int nr=0;
int i=0;
while(s[i]!=0)
{
if(s[i]=='/')
st[++top]=impartire,i++;
if(s[i]=='*')
st[++top]=inmultire,i++;
if(s[i]=='-')
st[++top]=scadere,i++;
if(s[i]=='+')
i++;
if(s[i]=='(')
st[++top]=paranteza,i++;
if(isdigit(s[i]))
{
nr=0;
while(isdigit(s[i]))
nr=nr*10+(s[i]-'0'),
i++;
if(st[top]==scadere)
nr*=-1,
top--;
while(st[top]==impartire && top)
{
top--;
nr=st[top]/nr;
top--;
}
while(st[top]==inmultire && top)
{
top--;
nr*=st[top];
top--;
}
st[++top]=nr;
}
if(s[i]==')')
{
nr=0;
while(st[top]!=paranteza && top)
nr+=st[top],
top--;
top--;
while(st[top]==inmultire && top)
{
top--;
nr*=st[top];
top--;
}
while(st[top]==impartire && top)
{
top--;
nr=st[top]/nr;
top--;
}
if(st[top]==scadere)
nr*=-1,
top--;
st[++top]=nr;
i++;
}
}
nr=0;
while(top)
{
nr+=st[top];
top--;
}
fout<<nr<<"\n";
}
int main()
{
Citire();
Rez();
return 0;
}