题目大意:
给出a, b两个用字符串表示的虚数,求a*b
题目思路:
偷了个懒,Python3的正则表达式匹配了一下,当然acm里肯定是不行的
1 class Solution: 2 def complexNumberMultiply(self, a, b): 3 """ 4 :type a: str 5 :type b: str 6 :rtype: str 7 """ 8 match = re.search(r'([+-]*d+)[+-]([+-]*d+)i$', a) 9 x1 = int(match.group(1)) 10 y1 = int(match.group(2)) 11 match = re.search(r'([+-]*d+)[+-]([+-]*d+)i$', b) 12 x2 = int(match.group(1)) 13 y2 = int(match.group(2)) 14 ans = '' 15 ans = ans + str(x1*x2 - y1*y2) + '+' 16 ans = ans + str(x1*y2 + x2*y1) + 'i' 17 return ans 18