码迷,mamicode.com
首页 > 其他好文 > 详细

537. Complex Number Multiplication

时间:2018-01-19 14:22:15      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:type   mat   elf   post   a*   ica   com   正则表达   sel   

技术分享图片

题目大意:

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

标签:type   mat   elf   post   a*   ica   com   正则表达   sel   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!