| #include <fstream>
#include <cstring>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");
int S[100],D[100],T[100],n;
char A[100];
void SRD(int v)
{
    if(strchr("+/-*%",A[v]) && v!=0)fout<<"(";
    if(S[v]) SRD(S[v]);
    fout<<A[v];
    if(D[v]) SRD(D[v]);
    if(strchr("+/-*%",A[v]) && v!=0)fout<<")";
}
int main()
{
    int n,v,pus;
    fin>>A;
    n=strlen(A)-1;
    T[0]=-1;
    for(int i=1;i<strlen(A);i++)
    {
        pus=0;
        v=0;
        while(!pus)
        {
            while(S[v] && strchr("/*-+%",A[S[v]])) v=S[v];
            if(S[v]==0) { S[v]=i; pus=1; T[i]=v; }
            else if(D[v] && strchr("/*-+%",A[D[v]])) v=D[v];
                 else {
                       if(D[v]==0) { D[v]=i; pus=1;T[i]=v;}
                       else { v=T[v];
                              while(T[v]!=-1 && !(D[v]==0 || strchr("/*-+%",A[D[v]])))
                                 v=T[v];
                              if(D[v]==0) { D[v]=i; pus=1;T[i]=v;}
                              else if(strchr("/*-+%",A[D[v]])) v=D[v];
                            }
                       }
        }
    }
    SRD(0);
    return 0;
}
 |