A complex number can be represented as a string on the form "real+imaginaryi" where:


	real is the real part and is an integer in the range [-100, 100].
	imaginary is the imaginary part and is an integer in the range [-100, 100].
	i2 == -1.


Given two complex numbers num1 and num2 as strings, return a string of the complex number that represents their multiplications.

&nbsp;
Example 1:

Input: num1 = "1+1i", num2 = "1+1i"
Output: "0+2i"
Explanation: (1 + i) * (1 + i) = 1 + i2 + 2 * i = 2i, and you need convert it to the form of 0+2i.


Example 2:

Input: num1 = "1+-1i", num2 = "1+-1i"
Output: "0+-2i"
Explanation: (1 - i) * (1 - i) = 1 + i2 - 2 * i = -2i, and you need convert it to the form of 0+-2i.


&nbsp;
Constraints:


	num1 and num2 are valid complex numbers.


class Solution:
    def complexNumberMultiply(self, num1: str, num2: str) -> str:
        i1=num1.index('+')
        i2=num2.index('+')
        a=int(num1[0:i1])
        x=int(num2[0:i2])
        b=int(num1[i1+1:len(num1)-1])
        y=int(num2[i2+1:len(num2)-1])
        ans1=a*x+(-1)*b*y
        ans2=a*y+b*x
        return str(ans1)+'+'+(str(ans2)+'i')
class Solution {
    public String complexNumberMultiply(String num1, String num2) {
        int val1 = Integer.parseInt(num1.substring(0, num1.indexOf('+')));
        int val2 = Integer.parseInt(num1.substring(num1.indexOf('+')+1,num1.length()-1));
        int val3 = Integer.parseInt(num2.substring(0, num2.indexOf('+')));
        int val4 = Integer.parseInt(num2.substring(num2.indexOf('+')+1,num2.length()-1));
        
        return "" + (val1*val3 - val2*val4) + "+" + (val1*val4 + val3*val2) + "i";
    }
}
class Solution {
public: 
    pair<int,int> seprateRealAndImg(string &s){
        int i = 0;
        string real,img;
        while(s[i] != '+') real += s[i++];
        while(s[++i] != 'i') img += s[i];
        
        return {stoi(real),stoi(img)};
    }
    string complexNumberMultiply(string num1, string num2) {
        pair<int,int> x = seprateRealAndImg(num1);
        pair<int,int> y = seprateRealAndImg(num2);
        
        int a1 = x.first,b1 = x.second;
        int a2 = y.first,b2 = y.second;
        
        int real = (a1 * a2) - (b1*b2);
        int img = (b1*a2) + (a1 * b2);
        
        return to_string(real) + "+" + to_string(img) + "i";
    }
};
var complexNumberMultiply = function(num1, num2) {
	let [realA, imaginaryA] = num1.split('+');
	let [realB, imaginaryB] = num2.split('+');
	imaginaryA = parseInt(imaginaryA);
	imaginaryB = parseInt(imaginaryB);
	const real = realA * realB - imaginaryA * imaginaryB;
	const imaginary = realA * imaginaryB + imaginaryA * realB;

	return `${real}+${imaginary}i`;
};
Complex Number Multiplication