详见: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. OpenGL之坐标转换(好文-清晰版)

    http://blog.csdn.net/zhongjling/article/details/8488844OpenGL之坐标转换(好文-清晰版)

  2. 调用html进行android布局

    1. [代码]html代码     <html>  <head>    <meta http-equiv="content-type" content ...

  3. 记录用到的一些linux命令和疑难解决

    1. 用gedit打开.bashrc larry@larry-Rev:~$ sudo gedit ~/.bashrc 2. ubuntu里安装软件有点像iOS里的Cydia,要添加软件源来在Ubunt ...

  4. 【USACO】Dining

    [题目链接] [JZXX]点击打开链接 [caioj]点击打开链接 [算法] 拆点+网络流 [代码] #include<bits/stdc++.h> using namespace std ...

  5. node.js版本管理(Win) --- nvm-window

    目录 1. 安装 2. 使用 1. 安装 去往Git链接:https://github.com/coreybutler/nvm-windows. 点击下载链接: 选择第一个nvm-noinstall. ...

  6. 【旧文章搬运】PsVoid中IrpCreateFile函数在Win7下蓝屏BUG分析及解决

    原文发表于百度空间,2010-04-05========================================================================== 这也许是我 ...

  7. 基于粒子群优化的无约束50维Rosenbrock函数求解

    基于粒子群优化的无约束50维Rosenbrock函数求解 一.问题重述 无约束50维的Rosenbrock函数可以描述如下: 其中, 0 要求按PSO算法思想设计一个该问题的求解算法. Rosenbr ...

  8. CodeForces 1098D. Eels

    题目简述:对一个非空正整数(可重)集合$S$,从中选出两个元素$a, b (a \leq b)$,将他们从$S$中删除并将$a+b$加入$S$,重复这个操作直到$S$中只剩下一个元素为止,称为一次[竞 ...

  9. 《剑指offer》面试题1:为类CMyString添加赋值运算符函数——C++拷贝构造函数与赋值函数

    题中已给出CMyString的类定义,要求写赋值运算符函数. #include<iostream> #include<cstring> using namespace std; ...

  10. E20190407-hm

    conclude  vt. 推断; 结束,终止; 议定; vi. 终了; 作出决定或达成协议; interjection  n. 叹词,感叹词; definitely  adv. 明确地; 确切地; ...