//1.遇到操作数,直接输出;
//2.栈为空时,遇到运算符,入栈;
//3.遇到左括号,将其入栈;
//4.遇到右括号,执行出栈操作,并将出栈的元素输出,直到弹出栈的是左括号,左括号不输出;
//5.遇到其他运算符’+”-”*”/’时,弹出所有优先级大于或等于该运算符的栈顶元素,然后将该运算符入栈;
//6.最终将栈中的元素依次出栈,输出。
//经过上面的步骤,得到的输出既是转换得到的后缀表达式。
//post[100]一定要初始化 post[100]={0};
#include <bits/stdc++.h>
using namespace std;
int k=0;
bool IsOperator(char ch)
{
if(ch=='+' || ch=='-' || ch=='*' || ch=='/')
return true;
return false;
}
int GetPriority(char ch,int flag)
{
if(ch=='+' || ch=='-'){
if(flag==1)
return 3;
return 2;
}
if(ch=='*' || ch=='/'){
if(flag==1)
return 5;
return 4;
}
if(ch=='('){
if(flag==1)
return 1;
return 6;
}
if(ch==')'){
if(flag==1)
return 6;
return 1;
}
}
void in_to_post(char in[],char post[])
{
stack <char> s;
for(int i=0;in[i]!='\0';i++){
if(in[i]>='0' && in[i]<='9'){
post[k++]=in[i];
post[k++]=' ';
continue;
}
else{
if(in[i]=='('){
s.push(in[i]);
continue;
}
if(in[i]==')'){
while(s.top()!='('){
post[k++]=s.top();
post[k++]=' ';
s.pop();
}
s.pop();
}
if(IsOperator(in[i])){
while(s.top()!='(' && GetPriority(in[i],0)<GetPriority(s.top(),1)){
post[k++]=s.top();
post[k++]=' ';
s.pop();
}
s.push(in[i]);
}
}
}
while(!s.empty()){
post[k++]=s.top();
post[k++]=' ';
s.pop();
}
return ;
}
int Cal(char x,char y,char op){
switch(op){
case '+': return x+y;
case '-': return x-y;
case '*': return x*y;
case '/': return x/y;
}
}
int SuffixExpress(char post[])
{
stack <char> s;
int x,y,z;
for(int i=0;post[i]!='\0';i++){
if(post[i]==' ')
continue;
if(post[i]>='0' && post[i]<='9')
s.push(post[i]-'0');
else{
x=s.top();
s.pop();
y=s.top();
s.pop();
z=Cal(y,x,post[i]);
s.push(z);
}
}
return z;
}
int main()
{
char in[1000],post[1000]={0};
in[0]='(';
gets(in+1);
in[strlen(in)]=')';
in[strlen(in)+1]='\0';
in_to_post(in,post);
//post[strlen(post)]='\0';
for(int i=0;in[i]!='\0';i++)
printf("%c",in[i]);
printf("\n");
for(int i=0;post[i+1]!='\0';i++)
printf("%c",post[i]);
printf("\n");
printf("%d\n",SuffixExpress(post));
return 0;
}