<p>A <a href="https://en.wikipedia.org/wiki/Complex_number" target="_blank">complex number</a> can be represented as a string on the form <code>&quot;<strong>real</strong>+<strong>imaginary</strong>i&quot;</code> where:</p>

<ul>
	<li><code>real</code> is the real part and is an integer in the range <code>[-100, 100]</code>.</li>
	<li><code>imaginary</code> is the imaginary part and is an integer in the range <code>[-100, 100]</code>.</li>
	<li><code>i<sup>2</sup> == -1</code>.</li>
</ul>

<p>Given two complex numbers <code>num1</code> and <code>num2</code> as strings, return <em>a string of the complex number that represents their multiplications</em>.</p>

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

<pre>
<strong>Input:</strong> num1 = &quot;1+1i&quot;, num2 = &quot;1+1i&quot;
<strong>Output:</strong> &quot;0+2i&quot;
<strong>Explanation:</strong> (1 + i) * (1 + i) = 1 + i2 + 2 * i = 2i, and you need convert it to the form of 0+2i.
</pre>

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

<pre>
<strong>Input:</strong> num1 = &quot;1+-1i&quot;, num2 = &quot;1+-1i&quot;
<strong>Output:</strong> &quot;0+-2i&quot;
<strong>Explanation:</strong> (1 - i) * (1 - i) = 1 + i2 - 2 * i = -2i, and you need convert it to the form of 0+-2i.
</pre>

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

<ul>
	<li><code>num1</code> and <code>num2</code> are valid complex numbers.</li>
</ul>

class Solution {
public:
    string complexNumberMultiply(string num1, string num2) {
        int mar=0,a1=0,a2=0,b1=0,b2=0,a1s=0,a2s=0,b1s=0,b2s=0;
        if(num1[0]=='-'){
            a1s=1;
        }
        for(int i=0;i<num1.size();i++){
            if(a1s && i==0 ){
                continue;
            }
            else if(num1[i]!='+'){
                if(mar==0){
                    // cout<<a1<<endl;
               a1 = a1 * 10 + (num1[i] - '0');
               }
                else if(num1[i]=='-'){
                    a2s=1;
                }
                else if(num1[i]!='i')
                a2 = a2 * 10 + (num1[i] - '0');
            }
            else{
                mar=1;
            }

        }


        mar=0;

        if(num2[0]=='-'){
            b1s=1;
        }
        for(int i=0;i<num2.size();i++){
            if(b1s && i==0 ){
                continue;
            }
            else if(num2[i]!='+'){
                if(mar==0){
                    // cout<<a1<<endl;
               b1 = b1 * 10 + (num2[i] - '0');
               }
                else if(num2[i]=='-'){
                    b2s=1;
                }
                else if(num2[i]!='i')
                b2 = b2 * 10 + (num2[i] - '0');
            }
            else{
                mar=1;
            }

        }
        if(a1s==1){
            a1=-a1;
        }
        if(b1s==1){
            b1=-b1;
        }
        if(a2s==1){
            a2=-a2;
        }
        if(b2s==1){
            b2=-b2;
        }
        cout<<a1<<"   "<<a2<<endl;
        cout<<b1<<"   "<<b2<<endl;
       int s1=a1*b1-a2*b2,s2=a1*b2+b1*a2;
        cout<<s1<<"   "<<s2<<endl;
       string ans;
       ans=ans+(to_string(s1));
       ans.push_back('+');
       ans=ans+(to_string(s2));
       ans.push_back('i');
       return ans;

    }
};
7300