详见: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. PL/SQL DEVELOPER执行计划的查看

    这里,我学到的一个很重要的东西,就是用PL/SQL DEVELOPER去看一条SELECT语句的执行计划,执行计划里面可以看到这条SELECT语句的开销.I/O操作开销等数值,可以很清晰地看到语句各个 ...

  2. [原创]Java开发在线打开编辑保存Word文件(支持多浏览器)

    Java调用PageOffice实现在线编辑保存Word文件(以jsp调用为例,支持SSM.SSH.SpringMVC等流行框架) 1. 下载PageOffice开发包:http://www.zhuo ...

  3. 并不对劲的CTS2019

    day0 没有C day1 t1:并不想简述题意 10分暴力走人 t2:有\(n\)个在\([1,D]\)内的均匀随机整数,问有多少的概率出现\(m\)对相同的 设\(f(i,j)\)表示考虑前\(i ...

  4. AtCoder Regular Contest 063 E:Integers on a Tree

    题目传送门:https://arc063.contest.atcoder.jp/tasks/arc063_c 题目翻译 给你一个树,上面有\(k\)个点有权值,问你是否能把剩下的\(n-k\)个点全部 ...

  5. CSS:CSS 颜色名

    ylbtech-CSS:CSS 颜色名 1.返回顶部 1. CSS 颜色名 所有浏览器都支持的颜色名. HTML 和 CSS 颜色规范中定义了 147 中颜色名(17 种标准颜色加 130 种其他颜色 ...

  6. libvirt kvm云主机监控

    libvirt

  7. Multipath TCP and load balancers

    Load balancers play a very important role in today’s Internet. Most Internet services are provided b ...

  8. Flutter实战视频-移动电商-43.详细页_补充首页跳转到详细页

    43.详细页_补充首页跳转到详细页 首页轮播点击到详细页 修改我们轮播这里的代码:SwiperDiy这个类这里的代码 return InkWell( onTap: (){ Application.ro ...

  9. 爬虫代码实现六-Queue队列实现循环抓取

    StartDSJCount : package com.dajiangtai.djt_spider.start; import java.util.List;import java.util.Queu ...

  10. lua中文教程【高级知识】

    一.编译和运行和调试 1.lua和其他解释型语言一样,先转换成为中间码再执行 2.dofile和loadfile的区别:loadfile编译返回不执行,返回错误代码:dofile执行,返回错误信息 3 ...