#include using namespace std; template class Stack { public: Stack (int m); ~Stack (); int StackIsFull(); int StackIsEmpty(); void Push(x e); void Pop(x& e); void PrintStack(); private: int maxsize; int top; x *p; }; int main(){ char f[64], e; cin.getline(f,64); Stack s(64); int i=0; while(f[i] != '\0') { if (f[i] == '(' || f[i] == '{' || f[i] == '[') s.Push(f[i]); else if (f[i] == ')' || f[i] == '}' || f[i] == ']'){ while(!s.StackIsEmpty()){ s.Pop(e); if (e != '(' && e != '{' && e != '[') cout << e; else break; } } else if (f[i] == '+' || f[i] == '-'){ while(!s.StackIsEmpty()){ s.Pop(e); if (e != '(' && e != '{' && e != '[') cout << e; else{ s.Push(e); break; } } s.Push(f[i]); } else if (f[i] == '*' || f[i] == '/'){ while(!s.StackIsEmpty()){ s.Pop(e); if (e != '(' && e != '{' && e != '[' && e != '+' && e != '-') cout << e; else{ s.Push(e); break; } } s.Push(f[i]); } else cout << f[i]; i++; } while(!s.StackIsEmpty()){ s.Pop(e); cout << e; } return 0; } template Stack::Stack(int m){ maxsize = m; top = -1; p = new x[maxsize]; } template Stack::~Stack(){ delete [] p; } template int Stack::StackIsFull(){ if (top == maxsize - 1) return 1; return 0; } template int Stack::StackIsEmpty(){ if (top == -1) return -1; return 0; } template void Stack::Push(x e){ if (!StackIsFull()){ top++; p[top] = e; } } template void Stack::Pop(x &e){ if (!StackIsEmpty()){ e = p[top]; top--; } } template void Stack::PrintStack(){ x e; if (!StackIsEmpty()){ Pop(e); PrintStack(); cout << e << endl; Push(e); } }