<p>Given a string <code>expression</code> representing an expression of fraction addition and subtraction, return the calculation result in string format.</p>

<p>The final result should be an <a href="https://en.wikipedia.org/wiki/Irreducible_fraction" target="_blank">irreducible fraction</a>. If your final result is an integer, change it to the format of a fraction that has a denominator <code>1</code>. So in this case, <code>2</code> should be converted to <code>2/1</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> expression = &quot;-1/2+1/2&quot;
<strong>Output:</strong> &quot;0/1&quot;
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> expression = &quot;-1/2+1/2+1/3&quot;
<strong>Output:</strong> &quot;1/3&quot;
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> expression = &quot;1/3-1/2&quot;
<strong>Output:</strong> &quot;-1/6&quot;
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li>The input string only contains <code>&#39;0&#39;</code> to <code>&#39;9&#39;</code>, <code>&#39;/&#39;</code>, <code>&#39;+&#39;</code> and <code>&#39;-&#39;</code>. So does the output.</li>
	<li>Each fraction (input and output) has the format <code>&plusmn;numerator/denominator</code>. If the first input fraction or the output is positive, then <code>&#39;+&#39;</code> will be omitted.</li>
	<li>The input only contains valid <strong>irreducible fractions</strong>, where the <strong>numerator</strong> and <strong>denominator</strong> of each fraction will always be in the range <code>[1, 10]</code>. If the denominator is <code>1</code>, it means this fraction is actually an integer in a fraction format defined above.</li>
	<li>The number of given fractions will be in the range <code>[1, 10]</code>.</li>
	<li>The numerator and denominator of the <strong>final result</strong> are guaranteed to be valid and in the range of <strong>32-bit</strong> int.</li>
</ul>

class Solution {
public:
int hcf(int a,int b){
    if(a>b) return hcf(b,a);
    for(int i=a;i>=1;i--){
        if(a%i==0 && b%i==0) return i;
    }
    return 1;
}
int lcm(int a,int b){
    return (a*b)/hcf(a,b);
}
    string fractionAddition(string expression) {
       vector<int>arr;
       vector<int>arr2;
       int i=0;
       
       while(i<expression.size()){
        int s=0;
        char p=expression[i];
        if(expression[i]=='+' || expression[i]=='-'){
         p=expression[i];
        i++;}
        while(i<expression.size() && expression[i]!='/') {
            s=s*10+(expression[i]-'0');
            i++;
        }
        if(p=='-') s=-s;
        arr.push_back(s);
        s=0;
        i++;
        while(i<expression.size() && expression[i]!='+' && expression[i]!='-') {
            s=s*10+(expression[i]-'0');
            i++;
        }
        // p=stoi(s);
        arr2.push_back(s);
        //arr2.push_back(stoi(s,nullptr, 10));

       }
       int l=1;
       for(int i=0;i<arr2.size();i++){
        l=lcm(l,arr2[i]);
       }
       int ans=0;
       for(int i=0;i<arr.size();i++){
        ans+=arr[i]*(l/arr2[i]);
       }
       if(ans%l==0) return to_string(ans/l)+'/'+'1';
       int ans2=ans;
       if(ans<0) ans2=-ans;
       int k=hcf(ans2,l);
       int num=ans/k;
       int dem=l/k;
       string a=to_string(num)+'/'+to_string(dem);
       return a;
       } 
    
};
7800