题意:此题就是需要重载一下几个运算符而已,看了大佬的才知道,注意把friend去掉
代码:
std::ostream& operator<<(std::ostream& os, const zrf_Ratio& z){
os<<z.num<<"/"<<z.den;
return os;
}
std::istream& operator>>(std::istream& is, zrf_Ratio& z){
is>>z.num>>z.den;
return is;
}
bool operator==(const zrf_Ratio& z1, const zrf_Ratio& z2){
return (z1.num==z2.num)&&(z1.den==z2.den);
}
bool operator<(const zrf_Ratio& z1, const zrf_Ratio& z2){
int k1 = z1.num*z2.den,k2 = z1.den*z2.num;
return k1<k2;
}