537 Complex Number Multiplication 复数乘法
详见:https://leetcode.com/problems/complex-number-multiplication/description/
C++:
class Solution {
public:
string complexNumberMultiply(string a, string b)
{
int n1 = a.size(), n2 = b.size();
auto p1 = a.find_last_of("+"), p2 = b.find_last_of("+");
int a1 = stoi(a.substr(0, p1)), b1 = stoi(b.substr(0, p2));
int a2 = stoi(a.substr(p1 + 1, n1 - p1 - 2));
int b2 = stoi(b.substr(p2 + 1, n2 - p2 - 2));
int r1 = a1 * b1 - a2 * b2, r2 = a1 * b2 + a2 * b1;
return to_string(r1) + "+" + to_string(r2) + "i";
}
};
参考:http://www.cnblogs.com/grandyang/p/6660437.html
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
题目大意: 给出a, b两个用字符串表示的虚数,求a*b 题目思路: 偷了个懒,Python3的正则表达式匹配了一下,当然acm里肯定是不行的 class Solution: def complexN ...
- LeetCode 537. 复数乘法(Complex Number Multiplication)
537. 复数乘法 537. Complex Number Multiplication 题目描述 Given two strings representing two complex numbers ...
- [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 复数相乘
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 ...
随机推荐
- 基于BASYS2的VHDL程序——数字钟
在编电子表时发现FPGA求余,取模只能针对2的次方.毕竟是数字的嘛! 时钟用到了动态刷新数码管.以一个大于50Hz的速度刷新每一个数码管. 因为数码管只有四个,只写了分针和秒针. 代码如下: libr ...
- ubuntu下安装cpython 0.2x
Quick installation of cython: Step 1: Update system: sudo apt-get update Step 2: Install: cython Ate ...
- 记录用到的一些linux命令和疑难解决
1. 用gedit打开.bashrc larry@larry-Rev:~$ sudo gedit ~/.bashrc 2. ubuntu里安装软件有点像iOS里的Cydia,要添加软件源来在Ubunt ...
- 七号信令中TUP协议的主要消息和故障问题
CIC码说明: TUP消息的路由标记: 为OPC 24位 DPC24位 CIC 12位,12位CIC 的低5为时隙号,其中后4位为SLC,高7位为系统号. CIC配置需要注意几个问题: ...
- 「NOIP2014」「Codevs3728」 联合权值(乱搞
3728 联合权值 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 输入描述 Input Description 输出描述 Ou ...
- Redis GEO 特性在 LBS 中的应用总结
什么是LBS LBS(Location Based Service),基于位置的服务. Redis和GEO Redis 是最热门的 nosql 数据库之一,它的最大特点就是快.所以在 LBS 这种需要 ...
- 3.sql中的向上递归和向下递归
1.向下递归 select * from table_name where 条件 connect by prior bmbm(本级关联条件)=sjbmbm(上级关联条件) start with bmb ...
- U盘安装 Linux 显示 “Faild to copy file from CD-ROM”
解决方案 使用 UltraISO 刻录 U盘做镜像时,出现这种情况.查阅别人的 blog,尝试手动挂载发现还是不能成功.然后使用 win32diskimager 重新刻录,再次安装时未出现该情况. 参 ...
- 量子隐形传态1 Quantum Teleportation
量子隐形传态是量子纠缠的又一个应用. 隐形传态,所谓隐形的意思就是没有物质介质就传递了信息,在经典世界,传递信息要有介质,光.电磁波或者其他的什么,但是在量子的世界里,我可以把信息传递给你,并且不传递 ...
- 2-1赋值运算符 & 2-2自增自减运算符 &2-3
2-1赋值运算符 先定义一个变量,把定义好的变量在赋值给另外一个变量.变向之间的互相赋值 2-2自增自减运算符 元素符,放在变量前和变量后的区别 先进行自增运算,再进行赋值运算.这里先进行num1的+ ...