#include
using namespace std;
#define maxsize 20
typedef struct
{
char *base;
char *top;
int stacksize;
}SqStack;
bool InitStack(SqStack &S)
{
S.base = new char[maxsize];
if (!S.base) return false;
S.top = S.base;
S.stacksize = maxsize;
return true;
}
bool Push(SqStack &S, char e)
{
if (S.top - S.base == S.stacksize)
return false;
*S.top = e;
S.top++;
return true;
}
bool Pop(SqStack &S, char &e)
{
if (S.top == S.base)
return false;
--S.top;
e = *S.top;
return true;
}
char GetTop(SqStack S)
{
char e;
if (S.top == S.base)
return false;
e = *(S.top - 1);
return e;
}
char bijiao(char a, char b)
{
if (a == '#' || a == '(')
{
if (b == ')') return '=';
return '<';
}
if (a == '+' || a == '-')
{
if (b == '*' || b == '/' || b == '(')
return '<';
else return '>';
}
if (a == '*' || a == '/')
{
if (b == '(')
return '<';
else return '>';
}
if (a == ')')
return '<';
}
bool StackEmpty(SqStack &S)
{
if (S.top == S.base)
return true;
else
return false;
}
int main()
{
SqStack S;
InitStack(S);
Push(S, '#');
int t;
char ch, k, m, n, p;
cin >> ch;
for (; ch != '\n';cin>>ch)
{
if (ch >= '0'&&ch <= '9') { t = ch - '0'; cout << t << ' '; }
else
{
switch (bijiao(GetTop(S), ch))
{
case '<':Push(S, ch); break;
case '>':while (GetTop(S) != '#')
{
if (GetTop(S) != '(')
{
Pop(S, m);
cout << m << ' ';
}
else Pop(S, n);
} break;
}
}
}
while (!StackEmpty(S))
{
if (GetTop(S) != '#')
{
Pop(S, p);
cout << p;
}
}
return 0;
}