Remove trailing zeros from the sum of two numbers ( Using Stack ) | Function to remove trailing zeros from the sum of two numbers ; Stores the sum of A and B ; Stores the digits ; Stores the equivalent string of integer N ; Traverse the string ; Push the digit at i in the stack ; While top element is '0 ; Pop the top element ; Stores the resultant number without tailing 0 's ; While s is not empty ; Append top element of S in res ; Pop the top element of S ; Reverse the string res ; Driver Code ; Input ; Function Call
def removeTailing ( A , B ) : NEW_LINE INDENT N = A + B NEW_LINE s = [ ] NEW_LINE strsum = str ( N ) NEW_LINE for i in range ( len ( strsum ) ) : NEW_LINE INDENT s . append ( strsum [ i ] ) NEW_LINE DEDENT DEDENT ' NEW_LINE INDENT while ( s [ - 1 ] == '0' ) : NEW_LINE INDENT s . pop ( ) NEW_LINE DEDENT res = " " NEW_LINE while ( len ( s ) != 0 ) : NEW_LINE INDENT res = res + ( s [ - 1 ] ) NEW_LINE s . pop ( ) NEW_LINE DEDENT res = list ( res ) NEW_LINE res . reverse ( ) NEW_LINE res = ' ' . join ( res ) NEW_LINE return res NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT A = 130246 NEW_LINE B = 450164 NEW_LINE print ( removeTailing ( A , B ) ) NEW_LINE DEDENT