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