<s> class Solution : <EOL> def fractionToDecimal ( self , numerator , denominator ) : <EOL> dvd , dvs = abs ( numerator ) , abs ( denominator ) <EOL> integer , decimal , dict = "<STR_LIT>" , "<STR_LIT>" , { } <EOL> if dvd > dvs : <EOL> integer = str ( dvd / dvs ) <EOL> dvd %= dvs <EOL> else : <EOL> integer = "<STR_LIT:0>" <EOL> if dvd > <NUM_LIT:0> : <EOL> integer += "<STR_LIT:.>" <EOL> idx = <NUM_LIT:0> <EOL> while dvd : <EOL> if dvd in dict : <EOL> decimal = decimal [ : dict [ dvd ] ] + "<STR_LIT:(>" + decimal [ dict [ dvd ] : ] + "<STR_LIT:)>" <EOL> break <EOL> dict [ dvd ] = idx <EOL> idx += <NUM_LIT:1> <EOL> dvd *= <NUM_LIT:10> <EOL> decimal += str ( dvd / dvs ) <EOL> dvd %= dvs <EOL> if ( numerator > <NUM_LIT:0> and denominator < <NUM_LIT:0> ) or ( numerator < <NUM_LIT:0> and denominator > <NUM_LIT:0> ) : <EOL> return "<STR_LIT:->" + integer + decimal <EOL> else : <EOL> return integer + decimal <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> print Solution ( ) . fractionToDecimal ( <NUM_LIT:1> , <NUM_LIT:9> ) <EOL> print Solution ( ) . fractionToDecimal ( - <NUM_LIT:50> , <NUM_LIT:8> ) <EOL> print Solution ( ) . fractionToDecimal ( <NUM_LIT> , <NUM_LIT:2> ) <EOL> print Solution ( ) . fractionToDecimal ( - <NUM_LIT> , - <NUM_LIT:2> ) </s>
