详见: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 复数乘法的更多相关文章

  1. LC 537. Complex Number Multiplication

    Given two strings representing two complex numbers. You need to return a string representing their m ...

  2. 【LeetCode】537. Complex Number Multiplication 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 日期 题目地址:https://leetcode.com/pr ...

  3. 537. Complex Number Multiplication

    题目大意: 给出a, b两个用字符串表示的虚数,求a*b 题目思路: 偷了个懒,Python3的正则表达式匹配了一下,当然acm里肯定是不行的 class Solution: def complexN ...

  4. LeetCode 537. 复数乘法(Complex Number Multiplication)

    537. 复数乘法 537. Complex Number Multiplication 题目描述 Given two strings representing two complex numbers ...

  5. [Swift]LeetCode537. 复数乘法 | Complex Number Multiplication

    Given two strings representing two complex numbers. You need to return a string representing their m ...

  6. [LeetCode] Complex Number Multiplication 复数相乘

    Given two strings representing two complex numbers. You need to return a string representing their m ...

  7. LeetCode Complex Number Multiplication

    原题链接在这里:https://leetcode.com/problems/complex-number-multiplication/description/ 题目: Given two strin ...

  8. [leetcode-537-Complex Number Multiplication]

    Given two strings representing two complex numbers. You need to return a string representing their m ...

  9. ural 1748 The Most Complex Number 和 丑数

    题目:http://acm.timus.ru/problem.aspx?space=1&num=1748 题意:求n范围内约数个数最多的那个数. Roughly speaking, for a ...

随机推荐

  1. Windows Server 2012 修改桌面图标

    在virtualbox 4.2.18中装了个Windows Server 2012 来体验下,结果发现桌面图标都不知道在哪改.在百度文库上找到了解决方法:http://wenku.baidu.com/ ...

  2. ansible-playbook 打通ssh无秘钥

    建议参考: http://www.cnblogs.com/jackchen001/p/6514018.html 这个代码清晰,效果佳! 参考链接: http://www.cnblogs.com/cao ...

  3. html5--3.19 新增的progress/meter元素

    html5--3.19 新增的progress/meter元素 学习要点 了解progress/meter元素的用法 progress元素 是HTML5中新增的元素,用来建立一个进度条 通常与Java ...

  4. Springboot框架中request.getInputStream()获取不到上传的文件流

    Springboot框架中用下面的代码,使用request.getInputStream()获取不到上传的文件流 @PostMapping("/upload_img") publi ...

  5. 数学题--On Sum of Fractions

    题目链接 题目意思: 定义v(n)是不超过n的最大素数, u(n)是大于n的最小素数. 以分数形式"p/q"输出 sigma(i = 2 to n) (1 / (v(i)*u(i) ...

  6. shell---rpm

    [root@master src]# rpm -qpl epel-release-latest-6.noarch.rpm         ##查询该rpm包安装了什么warning: epel-rel ...

  7. AutoIt中ControlFocus的使用

    在使用AutoIt最控件做自动化操作的时候,经常性的会碰到无法使用Windows Info工具获取控件的属性,但是我们又需要获取该控件的焦点,我们该怎么办呢? 方法1: 应用controlFocus方 ...

  8. VS2013Z学习java插件

    https://visualstudiogallery.msdn.microsoft.com/bc561769-36ff-4a40-9504-e266e8706f93 Bugs and Feature ...

  9. iOS中判断基础字符(大小写、数字等的判断)

    函数:isdigit 用法:#include 功能:判断字符c是否为数字 说明:当c为数字0-9时,返回非零值,否则返回零. 函数:islower 用法:#include 功能:判断字符c是否为小写英 ...

  10. Matrix Recurrence

    给定矩阵$A,B$,且有 $$f(0) = A ,f(i) =B * \prod_{i=w(i)}^{i-1}f(i)$$ 求f(n) 其中,当w(i)单增时,可以做到$O(n*m^3)$,注意要优化 ...