100% fast Fraction Addition and Subtraction
if code is understable well ,please upvote\nclass Rational{    \n    public :\n\n    int numerator=1;\n    int denominator=1; \n    Rational(int numerator, int 
if code is understable well ,please upvote\nclass Rational{    \n    public :\n\n    int numerator=1;\n    int denominator=1; \n    Rational(int numerator, int denominator) {\n        this -> numerator = numerator;\n        this -> denominator = denominator;\n    } \n\n    void add(Rational const &f2) {\n        int lcm = denominator * f2.denominator;\n        int x = lcm / denominator;\n        int y = lcm / f2.denominator;\n\n        int num = x * numerator + (y * f2.numerator);\n        int g=__gcd(abs(num),abs(lcm));\n\t\t// simplify the fraction\n        numerator = num/g;\n        denominator = lcm/g;\n\n    }    \n};\n\nclass Solution {\npublic:\n     \n    string fractionAddition(string str) {\n        int n=str.size();\n        int s1=1,s2=1;\n        int i=0;\n        if(str[i]==\'-\')s1=0,i++;\n        int nume=0,deno=1;\n        if(isdigit(str[i])){\n            nume=str[i++]-\'0\';\n\t\t\t// if numerator of fraction have two digit\n            if(isdigit(str[i])){\n                nume=nume*10+(str[i++]-\'0\');\n            }\n            if(s1==0)nume=-1*nume;\n            if(i<n && str[i]==\'/\'){\n                i++;\n                deno=str[i++]-\'0\';\n\t\t\t\t// if numerator of fraction have two digit\n                if(isdigit(str[i])){\n                    deno=deno*10+(str[i++]-\'0\');\n                }\n            }\n        }\n        cout<<nume<<"/"<<deno<<endl;\n        for(;i<n;){\n            int nume2=0,deno2=1;\n            if(isdigit(str[i])){\n                nume2=str[i++]-\'0\';\n\t\t\t\t// if numerator of fraction have two digit\n                if(isdigit(str[i])){\n                    nume2=nume2*10+(str[i++]-\'0\');\n                }\n                if(i<n && str[i]==\'/\'){\n                    i++;\n                    deno2=str[i++]-\'0\';\n\t\t\t\t\t// if numerator of fraction have two digit\n                    if(isdigit(str[i])){\n                        deno2=deno2*10+(str[i++]-\'0\');\n                    }\n                }\n            }\n            else{\n                if(str[i]==\'-\')s2=0;\n    \n                i++;\n                continue;\n            }\n             \n            if(s2==0)nume2=-1*nume2; \n            Rational f1(nume, deno);\n\t        Rational f2(nume2, deno2);\n            f1.add(f2); // add fractional values\n\t\t\t//update these fractions \n            nume=f1.numerator;\n            deno=f1.denominator \n            s2=1;\n        }\n         \n        string res="";\n        res+=to_string(nume);\n        res+="/";\n        if(nume==0){\n            res+=to_string(1);\n        }\n        else res+=to_string(deno);\n        return res;\n    }\n};
['C++']