<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 r1 = 0, i1 = 0, r2 = 0, i2 = 0;
        // first string
        // real
        int i = 0;
        if(num1[0] == '-') i++;
        while(num1[i] != '+') {
            r1 *= 10;
            r1 += num1[i]-'0';
            i++;
        }
        if(num1[0] == '-') r1 *= -1;
        // imaginary
        i++; // the plus sign
        int j = i;
        if(num1[i] == '-') j++;
        while(num1[j] != 'i') {
            i1 *= 10;
            i1 += num1[j]-'0';
            j++;
        }
        if(num1[i] == '-') i1 *= -1;
        // second string
        // real
        i = 0;
        if(num2[0] == '-') i++;
        while(num2[i] != '+') {
            r2 *= 10;
            r2 += num2[i]-'0';
            i++;
        }
        if(num2[0] == '-') r2 *= -1;
        // imaginary
        i++; // the plus sign
        j = i;
        if(num2[i] == '-') j++;
        while(num2[j] != 'i') {
            i2 *= 10;
            i2 += num2[j]-'0';
            j++;
        }
        if(num2[i] == '-') i2 *= -1;
        // now the math part
        string res = "";
        res += to_string(r1*r2 - i1*i2); // real multiplication
        res += '+';
        res += to_string(r1*i2 + i1*r2); // i multiplication
        res += 'i';
        cout << r1 << i1 << r2 << i2;
        return res;
        
    }
};
7600