/*
* @lc app=leetcode.cn id=537 lang=typescript
*
* [537] 复数乘法
*/
// @lc code=start
function complexNumberMultiply(num1: string, num2: string): string {}
// @lc code=end
function complexNumberMultiply(num1: string, num2: string): string {
const [[a1, b1], [a2, b2]] = [num1, num2].map(num => num.split('+').map(i => parseInt(i)))
return `${a1 * a2 - b1 * b2}+${a1 * b2 + a2 * b1}i`
}
test.each([
{ input: { num1: '1+1i', num2: '1+1i' }, output: '0+2i' },
{ input: { num1: '1+-1i', num2: '1+-1i' }, output: '0+-2i' },
])('input: num1 = $input.num1, num2 = $input.num2', ({ input: { num1, num2 }, output }) => {
expect(complexNumberMultiply(num1, num2)).toEqual(output)
})