题目:
解题代码:
func complexNumberMultiply(num1 string, num2 string) string {
// 先获取实部数值
var a1,a2,b1,b2 int
f := func(c rune) bool {
if c == '+' || c == 'i'{
return true
} else {
return false
}
}
one := strings.FieldsFunc(num1, f)
two := strings.FieldsFunc(num2, f)
a1,_ = strconv.Atoi(one[0])
a2,_ = strconv.Atoi(one[1])
b1,_ = strconv.Atoi(two[0])
b2,_ = strconv.Atoi(two[1])
// 计算
aa := a1 * b1 - a2 * b2
bb := a1 * b2 + a2 * b1
return strconv.Itoa(aa) + "+" + strconv.Itoa(bb) + "i"
}