4.26打卡

发布时间 2023-04-26 23:21:06作者: yblll

 

#include<bits/stdc++.h>
using namespace std;
class number
{
    int fz, fm;
    friend number operator+(number &n1,number &n2);
    public:
    number(int a=0,int b=1)
    {
        fz=a;
        fm=b;
    }
    friend int gcd(int a,int b);
    friend int min_gb(number &n1,number &n2);
    int show()
    {
        cout<<fz;
        if(fm!=1) 
        {
            cout<<" "<<fm;
        }
    }
};

int gcd(int a, int b)
{
    if(b==0)
    {
        return a;
    }
    else
    {
        return gcd(b,a%b);
    }
}
    
    int min_gb(number &n1,number &n2)
    {
        return n1.fm*n2.fm/gcd(n1.fm,n2.fm);
    }
    
    number operator+(number &n1,number &n2)
    {
        number nn;
        int a=min_gb(n1,n2);
        nn.fm=a;
        nn.fz=(a/n1.fm)*n1.fz+(a/n2.fm)*n2.fz;
        int b=gcd(nn.fz,nn.fm);
        if(b!=1)
        {
            nn.fz=nn.fz/b;
            nn.fm=nn.fm/b;
        }
        return nn;
    }
    
    int main()
    {
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        number num1(a,b);
        number num2(c,d);
        number num3;
        num3=num1+num2;
        num3.show();
    }

 

#include<bits/stdc++.h>
using namespace std;
class CComplex
{
    private:
    double real;
    double imag;
    double model;
    public:
    CComplex(double a= 0, double b=0):real(a),imag(b)
    {
        model=sqrt(real*real+imag*imag);
    };
    bool operator>(const CComplex& c)
    {
        double temp;
        temp=sqrt(c.real*c.real+c.imag*c.imag);
        if(model>temp)
        {
            return true;
        }
        else{
            return false;
        }
    }
};

int main()
{
    double a,b,c,d;
    cin>>a>>b>>c>>d;
    while(a||b||c||d)
    {
        CComplex c1(a,b),c2(c,d);
        bool boolean=c1>c2;
        cout.setf(ios_base::boolalpha);
        cout<<boolean<<endl;
        cin>>a>>b>>c>>d;
    }
    return 0;
}