首页 > 其他 > 详细

537. Complex Number Multiplication

时间:2018-01-19 13:08:12      阅读:221      评论:0      收藏:0      [点我收藏+]

技术分享图片

题目大意:

    给出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         

 

537. Complex Number Multiplication

原文:https://www.cnblogs.com/liwenchi/p/8316208.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!