class Solution {
public:
string fractionToDecimal(int numerator, int denoinator) {
string ans_z="",ans_x="";
unordered_map<long long,int>mp;
long long Lnumerator=(long long )numerator;
long long Ldenoinator=(long long)denoinator;
//能整除下的情况
if(Lnumerator%Ldenoinator==0){
return to_string(Lnumerator/Ldenoinator);
}
//符号
if(Lnumerator>0^Ldenoinator>0){
ans_z+='-';
}
//整数部分
Lnumerator=abs(Lnumerator);
Ldenoinator=abs(Ldenoinator);
int num_zheng=Lnumerator/Ldenoinator;
ans_z+=to_string(num_zheng);
ans_z+=".";
//小数部分
int idx=0;
long long mod=Lnumerator%Ldenoinator;
while(mod!=0&&mp.find(mod)==mp.end()){
mp[mod]=idx;
mod*=10;
ans_x+=to_string(mod/Ldenoinator);
mod=mod%Ldenoinator;
idx++;
}
if(mod!=0){
int insertIdx=mp[mod];
ans_x=ans_x.substr(0,insertIdx)+'('+ans_x.substr(insertIdx);
ans_x+=')';
}
ans_z+=ans_x;
return ans_z;
}
};