#include<iostream>
#include<stdio.h>
#include<fstream>
#include<cstdlib>
using namespace std;
#define MAXSIZE 1000
typedef struct
{
char *top;
char *base;
int stacksize;
} Sq;
Sq S1;
void InitStack(Sq &S1)
{
S1.base = new char[MAXSIZE];
if(!S1.base)
exit(0);
S1.top = S1.base;
S1.stacksize = MAXSIZE;
}
void push(Sq &S1, char g)
{
*S1.top++ = g;
}
char pop(Sq &S1)
{
char g;
g = *--S1.top;
return g;
}
int main()
{
int i;
char ch[301];
scanf("%s",ch);
InitStack(S1);
for(i=0;ch[i]!='\0';i++)
{
if(ch[i]!='+'&&ch[i]!='-'&&ch[i]!='*'&&ch[i]!='/'&&ch[i]!='('&&ch[i]!=')')
{
printf("%c",ch[i]);
}
else if(ch[i]=='('){push(S1,ch[i]);}
else if(ch[i]==')')
{
while(*(S1.top-1)!='(') printf("%c",pop(S1));pop(S1);
}
else if(ch[i]=='+'||ch[i]=='-'||ch[i]=='*'||ch[i]=='/')
{
if(S1.top==S1.base) push(S1,ch[i]);
else
{
if(ch[i]=='*'||ch[i]=='/')
{
while(*(S1.top-1)!='+'&&*(S1.top-1)!='-'&&*(S1.top-1)=='('&&S1.top!=S1.base)
{
printf("%c",pop(S1));
}
push(S1,ch[i]);
}
else
{
while(*(S1.top-1)!='('&&S1.top!=S1.base) printf("%c",pop(S1));
push(S1,ch[i]);
}
}
}
}
while(S1.top!=S1.base) printf("%c",pop(S1));
printf("\n");
return 0;
}
#include<stdio.h>
#include<fstream>
#include<cstdlib>
using namespace std;
#define MAXSIZE 1000
typedef struct
{
char *top;
char *base;
int stacksize;
} Sq;
Sq S1;
void InitStack(Sq &S1)
{
S1.base = new char[MAXSIZE];
if(!S1.base)
exit(0);
S1.top = S1.base;
S1.stacksize = MAXSIZE;
}
void push(Sq &S1, char g)
{
*S1.top++ = g;
}
char pop(Sq &S1)
{
char g;
g = *--S1.top;
return g;
}
int main()
{
int i;
char ch[301];
scanf("%s",ch);
InitStack(S1);
for(i=0;ch[i]!='\0';i++)
{
if(ch[i]!='+'&&ch[i]!='-'&&ch[i]!='*'&&ch[i]!='/'&&ch[i]!='('&&ch[i]!=')')
{
printf("%c",ch[i]);
}
else if(ch[i]=='('){push(S1,ch[i]);}
else if(ch[i]==')')
{
while(*(S1.top-1)!='(') printf("%c",pop(S1));pop(S1);
}
else if(ch[i]=='+'||ch[i]=='-'||ch[i]=='*'||ch[i]=='/')
{
if(S1.top==S1.base) push(S1,ch[i]);
else
{
if(ch[i]=='*'||ch[i]=='/')
{
while(*(S1.top-1)!='+'&&*(S1.top-1)!='-'&&*(S1.top-1)=='('&&S1.top!=S1.base)
{
printf("%c",pop(S1));
}
push(S1,ch[i]);
}
else
{
while(*(S1.top-1)!='('&&S1.top!=S1.base) printf("%c",pop(S1));
push(S1,ch[i]);
}
}
}
}
while(S1.top!=S1.base) printf("%c",pop(S1));
printf("\n");
return 0;
}