Parsing inputString=inputString.replace(“,”) inputString=inputString.replace(“\t”,”) #inputString=inputString.replace(“()”,“”) '''======

Parsing inputString=inputString.replace(“,”) inputString=inputString.replace(“\t”,”) #inputString=inputString.replace(“()”,“”) '''======,parsing,tree,expression,Parsing,Tree,Expression,inputString=inputString.replace(“,”) inputString=inputString.replace(“\t”,”) #inputString=inputString.replace(“()”,“”) '''===================================================================''之前的子字符串是表达式树,'/'之后的子字符串是操作序列 #posOfSlash=斜线字符的位置 posOfSlash

inputString=inputString.replace(“,”) inputString=inputString.replace(“\t”,”) #inputString=inputString.replace(“()”,“”) '''===================================================================''之前的子字符串是表达式树,'/'之后的子字符串是操作序列 #posOfSlash=斜线字符的位置 posOfSlash=inputString.find('/')) 如果(posOfSlash==-1): 打印(输入字符串) 返回 #expressionTree=表达式树 expressionTree=inputString[0:posOfSlash] #seqOfOp=要执行的操作顺序 seqOfOp=inputString[posOfSlash+1:] '''================如果操作序列为空,则按原样打印表达式树===================='' 如果(len(sekofop)==0): 打印(expressionTree) 返回 '''=================================================''从操作序列中删除所有RR对 seqOfOp=seqOfOp.替换(r+r') '''=========================================================================''所有多个将替换为一个 while(seqOfOp.find(s+s)!=-1): seqOfOp=seqOfOp.更换(s+s,s) '''=============如果要执行操作R,则调用operationReverse(),否则如果要执行操作S,则调用OperationsSimplify()===================''' 对于范围(0,len(seqOfOp))内的x: 如果(seqOfOp[x]==r): expressionTree=operationReverse(expressionTree) 其他: expressionTree=操作简化(expressionTree) 打印(expressionTree) 返回 ''=======表示操作r和s的全局变量r和s'' r='r' s='s' 尽管如此: 尝试: inputString=input() '''=========================================================================''调用函数解决方案 解决方案(输入字符串) 除EOFError外: 打破
可能:哦。。。其实我现在不记得了。。。我一年前就解决了
'''
Examples are as follows :
INPUT:
(AB)(C(DE))/SS
(((AB)C)D)E/SS
(((AB)C)D)E/SR
(AB)C((DE)F)/SRS
(AB(CD((EF)G)H))(IJ)/SRS
(AB(CD((EF)G)H))(IJ)/SSSRRRS
(A(B(C)D)E(FGH(IJ)))/SRRSSRSSRRRSSRS
(A(BC(D(E((Z)K(L)))F))GH(IJK))/S
-------------------------------
OUTPUT:
AB(C(DE))
ABCDE
EDCBA
FEDCBA
JI(H(GFE)DC)BA
JI(H(GFE)DC)BA
JIHFGE(D(C)B)A
A(BC(D(E(ZK(L)))F))GH(IJK)/S
'''



'''
operationReverse function returns a reversed expression tree 
Example :  AB(CD) -> (DC)BA
'''
def operationReverse(expression):
    '''============== Reversing the whole expressions ================'''
    expression = expression[::-1] 
    expression = list(expression)

    '''========= Replace Closing brace with Opening brace and vice versa ========='''
    for x in range(0, len(expression)):
        if(expression[x] != ')' and expression[x] != '('):
            continue
        elif(expression[x] == ")"):
            expression[x] = "("
        else:
            expression[x] = ")"

    expression = ''.join(expression)
    return expression


'''
operationSimplify function returns a simplified expression tree 
Example :  (AB)(C(DE)) -> AB(C(DE))
operationSimplify uses recursion
'''
def operationSimplify(expression):

    '''========= If no parenthesis found then return the expression as it is because it is already simplified ========='''
    '''========= This is also the base condition to stop recursion ============='''
    if(expression.find('(')==-1):
        return expression


    '''If 1st character is opening brace then find its correspoinding closing brace and remove them and call the function by passing the values between the opening and                 closing brace'''

    if(expression[0] == '('):
        x = 1
        #numOfOpeningBrackets = maintains the count of opening brackets for finding it's corresponding closing bracket
        numOfOpeningBrackets = 1
        while(x < len(expression)):
            if(expression[x] != ')' and expression[x] != '('):
                x = x + 1
                continue
            elif(expression[x] == "("):
                numOfOpeningBrackets = numOfOpeningBrackets + 1
                x = x + 1
            else:
                numOfOpeningBrackets = numOfOpeningBrackets - 1   
                if(numOfOpeningBrackets == 0):
                    posOfCloseBracket = x
                    break         
                x = x + 1 
        expression = operationSimplify(expression[1:posOfCloseBracket]) + expression[posOfCloseBracket+1:]

    '''========= If no parenthesis found then return the expression as it is because it is already simplified ========='''
    if(expression.find('(')==-1):
        return expression

    '''========= Find the opening brace and it's closing brace and new expression tree will be concatenation of start of string till opening brace including the brace and string       with in the opening brace and closing brace passed as an argument to the function itself and the remaining string ========='''
    x = 0
    #numOfOpeningBrackets = maintains the count of opening brackets for finding it's corresponding closing bracket
    recursion = False
    numOfOpeningBrackets = 0
    while (x < len(expression)):
        if(expression[x] != ')' and expression[x] != '('):
                x = x + 1
        elif(expression[x] == "("):
            if(numOfOpeningBrackets == 0 or recursion == True):
                numOfOpeningBrackets = 0
                recursion = False
                posOfStartBracket = x
                y = x
            numOfOpeningBrackets = numOfOpeningBrackets + 1
            x = x + 1
        else:
            numOfOpeningBrackets = numOfOpeningBrackets - 1 
            if(numOfOpeningBrackets == 0):
                posOfCloseBracket = x 
                x = y 
                expression=expression[0:posOfStartBracket+1]+operationSimplify(expression[posOfStartBracket+1:posOfCloseBracket])+expression[posOfCloseBracket:]
                recursion = True
            x = x + 1
    return expression


'''
solution fucntion prints the final result  
'''
def solution(inputString):
    '''========= Remove the spaces from the input ==============='''
    #inputString = inputString.replace("\n","")
    inputString = inputString.replace(" ","")
    inputString = inputString.replace("\t","")
    #inputString = inputString.replace("()","")

    '''=============== The substring before '/' is expression tree and substring after '/' is sequence of operations  ======================'''

    #posOfSlash = Position Of Slash Character
    posOfSlash = inputString.find('/')
    if(posOfSlash == -1):
        print (inputString)
        return
    #expressionTree = Expression Tree
    expressionTree = inputString[0:posOfSlash]
    #seqOfOp = sequence of operations to be performed
    seqOfOp = inputString[posOfSlash+1:]

    '''============ If sequence Of Operations is empty then print the expression tree as it is ============== '''
    if(len(seqOfOp)==0):
        print(expressionTree)
        return


    '''============= Removing all the pairs of RR from the sequence Of Operations =================='''   
    seqOfOp = seqOfOp.replace(r+r,'')

    '''============ All mulptiple S are replaced by one single S ================'''   
    while(seqOfOp.find(s+s) != -1):
        seqOfOp = seqOfOp.replace(s+s,s)

    '''============ If to perform operation R then call operationReverse() else if to perform operation S call operationSimplify() ================'''
    for x in range (0 , len(seqOfOp)):
        if(seqOfOp[x] == r):
            expressionTree = operationReverse(expressionTree)
        else :
            expressionTree = operationSimplify(expressionTree)
    print(expressionTree)
    return



'''======= Global variables r and s representing operations R and S'''
r = 'R'
s = 'S' 
while True:
    try:
        inputString = input()
        '''==================== Calling function solution  ======================'''
        solution(inputString)
    except EOFError:
        break