537. Complex Number Multiplication

537. Complex Number Multiplication

题目大意:

    给出a, b两个用字符串表示的虚数,求a*b

题目思路:

    偷了个懒,Python3的正则表达式匹配了一下,当然acm里肯定是不行的

 class Solution:
def complexNumberMultiply(self, a, b):
"""
:type a: str
:type b: str
:rtype: str
"""
match = re.search(r'([+-]*\d+)[+-]([+-]*\d+)i$', a)
x1 = int(match.group(1))
y1 = int(match.group(2))
match = re.search(r'([+-]*\d+)[+-]([+-]*\d+)i$', b)
x2 = int(match.group(1))
y2 = int(match.group(2))
ans = ''
ans = ans + str(x1*x2 - y1*y2) + '+'
ans = ans + str(x1*y2 + x2*y1) + 'i'
return ans
上一篇:Windows服务模式下tomcat开启远程调试


下一篇:MySQL技术内幕读书笔记(二)——InnoDB存储引擎