Topic request

Compute the product of two complex numbers.

Refer to the answer key

This problem feels very simple, mainly is the expression of the complex number for analysis, and then apply the formula, the output result can be.

class Solution:
    def complexNumberMultiply(self, a, b) :
        """ :type a: str :type b: str :rtype: str """
        (x,y) = a.split("+")
        (m,n) = b.split("+")
        (y, k) = y.split("i")
        (n, k) = n.split("i")
        # print( (int)x*(int)m - (int)n*(int)y )
        return str( int(x)*int(m) - int(n)*int(y) ) + "+" + str( int(x)*int(n) + int(m)*int(y) ) + "i"
Copy the code

This article is the author’s original, if you think this article is helpful to you, please feel free to tip, your support will encourage me to continue to create.

2. Complex Number