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
537. Complex Number Multiplication的更多相关文章
- LC 537. Complex Number Multiplication
Given two strings representing two complex numbers. You need to return a string representing their m ...
- 【LeetCode】537. Complex Number Multiplication 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 日期 题目地址:https://leetcode.com/pr ...
- 537 Complex Number Multiplication 复数乘法
详见:https://leetcode.com/problems/complex-number-multiplication/description/ C++: class Solution { pu ...
- LeetCode 537. 复数乘法(Complex Number Multiplication)
537. 复数乘法 537. Complex Number Multiplication 题目描述 Given two strings representing two complex numbers ...
- [LeetCode] Complex Number Multiplication 复数相乘
Given two strings representing two complex numbers. You need to return a string representing their m ...
- [Swift]LeetCode537. 复数乘法 | Complex Number Multiplication
Given two strings representing two complex numbers. You need to return a string representing their m ...
- LeetCode Complex Number Multiplication
原题链接在这里:https://leetcode.com/problems/complex-number-multiplication/description/ 题目: Given two strin ...
- [leetcode-537-Complex Number Multiplication]
Given two strings representing two complex numbers. You need to return a string representing their m ...
- ural 1748 The Most Complex Number 和 丑数
题目:http://acm.timus.ru/problem.aspx?space=1&num=1748 题意:求n范围内约数个数最多的那个数. Roughly speaking, for a ...
随机推荐
- html总结:float实现span和input输入框同行
例: <input type="text" name="ytdwname" value="<%=user.getYtdwname() %& ...
- 为github添加ssh key
用git关联github上的远程仓库前需要先为github添加ssh key 一.检查本机是否生成ssh key 本地查找.ssh文件,其中id_rsa.pub中的内容就是ssh key 二.为git ...
- JDK8 的FullGC 之 metaspace
JDK8 的FullGC 之 metaspace - 简书https://www.jianshu.com/p/1a0b4bf8d498
- 剑指offer(8)
题目: 输入一个整数,输出该数二进制表示中1的个数.其中负数用补码表示. 思路: 第一反应想到的是把数右移,每一位与1相与,然后判断个数,但是若输入的为负数,会出现死循环现象. 所以我们设置一个标志量 ...
- python学习笔记(3)--turtle简单绘制
参考:大学生mooc 北京理工大学的python程序与设计课程 蟒蛇绘制代码如下: #pythonDraw.py import turtle turtle.setup(650,350,200,200) ...
- sonar结合jenkins
一.下载jenkins插件 二.系统设置 三.获取token值 4.调整 Jenkins 构建设置
- tomcat 与 nginx,apache的区别
tomcat 与 nginx,apache的有什么区别 回答一: 题主说的Apache,指的应该是Apache软件基金会下的一个项目——Apache HTTP Server Project:Nginx ...
- delphi怎样在关闭程序时弹出窗口?
我想在关闭delphi编译的程序时,弹出“您是否确实要退出的窗口”点击否不退出,是退出 在主窗体的CloseQuery事件里,使用messagebox进行提示,根据选择的按钮对Canclose进行设置 ...
- SQL字段类型bit 查询时注意
sql 查询时 字段=1 或 字段=0 c# 里也是
- Sql server 系统表
sql server系统表详细说明 SQL Server 用户库中系统表说明 名称 说明 备注 syscolumns 每个表和视图中的每列在表中占一行,存储过程中的每个参数在表中也占一行. sys ...