分数模板 发表于 2019-10-05 | 阅读次数: 本文字数: 5.9k | 阅读时长 ≈ 5 分钟 直接上代码点击显/隐代码 1234567891011121314151617181920212223#include<bits/stdc++.h>using namespace std;inline int gcd(int a,int b) {return b==0||a==0?a+b:gcd(b,a%b);}struct frac{ int x,y; inline frac yue() {return (frac){x/gcd(x,y),y/gcd(x,y)};} inline frac dao() {return (frac){y,x};} inline void read() {scanf("%d%d",&x,&y);} inline void write() {printf("%d/%d\n",x,y);} inline bool operator<(frac a) const {return x*a.y<y*a.x;} inline bool operator==(frac a) const {return x*a.y==y*a.x;} inline bool operator<=(frac a) const {return *this<a||*this==a;} inline bool operator>(frac a) const {return !(*this<=a);} inline bool operator>=(frac a) const {return !(*this<a);} inline bool operator!=(frac a) const {return !(*this==a);} inline frac operator+(frac a) const {return (frac){x*a.y+y*a.x,y*a.y}.yue();} inline frac operator-(frac a) const {return (frac){x*a.y-y*a.x,y*a.y}.yue();} inline frac operator*(frac a) const {return (frac){x*a.x,y*a.y}.yue();} inline frac operator/(frac a) const {return *this*a.dao();}};int main(){}