详见: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. 手写Future模式

    根据前面我所说的Futrue模式,手写一个: 分别对应的Java代码,大家拿来参考: package FutureTest; //公共data数据接口 public abstract class Da ...

  2. html5--3.17 新增的表单重写

    html5--3.17 新增的表单重写 学习要点 对form元素的属性做一个小结,对个别属性进行一点补充 重点掌握新增的表单重写 form元素的属性小结 action/method/enctype/n ...

  3. 烂笔头——JAVA.String

    人们说 Sting+ 的效率很低 String+的编译步骤是: new StringBuilder() new String.valueof() StringBuilder.<init> ...

  4. python虚拟环境管理包virtualenvwrapper

    1.打开cmd 2.安装virtualenvwrapper pip install virtualenvwrapper-win 3.配置虚拟环境的位置 新建系统变量默认在c盘 4.新建虚拟环境 mkv ...

  5. HttpClient入门教程

    HttpClient使用详解与实战一:https://www.jianshu.com/p/375be5929bed

  6. bzoj4520

    KD-tree+堆 多年大坑 KD-tree已经是半年前学的了,忘记了.这道题当时一直T,今天重新抄了一遍,A了 KD-tree过程:1.建树:每次依次按x,y划分平面,像二叉搜索树一样建树,每个点维 ...

  7. python zlib字符串压缩

    在做网络程序时,可以对字符串进行压缩来节省带宽 项目中用到 {"compress": <压缩标记>, "result":[[设备类型.设备ID, 设 ...

  8. Linux日志分割脚本

    该脚本的功能是定时分割日志文件 #!/usr/bin/env bash #定时分割清理日志文件 #usage="Usage: logrotate (start|stop) file (lin ...

  9. java集合框架之Collection

    参考http://how2j.cn/k/collection/collection-collection/366.html Collection是 Set List Queue和 Deque的接口Qu ...

  10. java集合框架之ArrayList与LinkedList的区别

    参考http://how2j.cn/k/collection/collection-arraylist-vs-linkedlist/690.html#nowhere ArrayList和LinkedL ...