Pagini recente » Cod sursa (job #2245581) | Cod sursa (job #2651293) | Cod sursa (job #1833597) | Cod sursa (job #867017) | Cod sursa (job #3214805)
#include <fstream>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
ifstream fin("evaluare.in");
ofstream fout("evaluare.out");
string s;
const int bracket = 1e9 + 1, divide = 1e9 + 2, times = 1e9 + 3, Minus = 1e9 + 4;
int st[100001],top;
int main()
{
fin >> s;
for (int i = 0; i < s.size(); i++)
{
if (s[i] == '+')
continue;
else if (s[i] == '-')
st[++top] = Minus;
else if (s[i] == '*')
st[++top] = times;
else if (s[i] == '/')
st[++top] = divide;
else if (s[i] == '(')
st[++top] = bracket;
else
{
int x = 0;
if (isdigit(s[i]))
{
while (isdigit(s[i]))
x = x*10 + (s[i++] - '0');
i--;
}
else
{
while (st[top] != bracket)
x += st[top--];
top--;
}
if (top == 0)
st[++top] = x;
else if (st[top] == Minus)
st[top] = -x;
else if (st[top] == times)
{
st[top - 1] *= x;
top--;
}
else if (st[top] == divide)
{
st[top - 1] /= x;
top--;
}
else
st[++top] = x;
}
}
int s = 0;
for (int i = 1; i <= top; i++)
s += st[i];
fout << s;
return 0;
}