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 ...
随机推荐
- HDU1873 看病要排队 —— 优先队列(STL)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1873 题解: 题目已经说出了解题方法:优先队列.但是之前没有学过优先队列,而且这题还是在现场赛做的.由 ...
- BZOJ 1623 [Usaco2008 Open]Cow Cars 奶牛飞车:贪心
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1623 题意: 编号为1到N的N只奶牛正各自驾着车打算在牛德比亚的高速公路上飞驰.高速公路有 ...
- [原创]Java开发如何在线打开Word文件
此方案使用了PageOffice产品实现在线打开Word文档: 1. 首先从PageOffice官网下载产品开发包,http://www.zhuozhengsoft.com/dowm/ ,下载Page ...
- OpenCV——PS滤镜 水波效果
// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...
- 并不对劲的loj3048:p5283:[十二省联考]异或粽子
题目大意 有\(n\)(\(n\leq5\times10^5\))个数\(a_1,a_2,...a_n\)(\(a_i\leq 2^{32}-1\)) 求区间异或和前\(k(k\leq2\times1 ...
- HDU3440 House Man (差分约束)
In Fuzhou, there is a crazy super man. He can’t fly, but he could jump from housetop to housetop. To ...
- compileSdkVersion, minSdkVersion 和 targetSdkVersion详解
API level API level是一个整数,它指的是我们使用的框架(Framework)的版本,也就是我们使用的sdk中的各个平台下的android.jar. 但是这个API level又和An ...
- 上传图片时压缩图片 - 前端(canvas)做法
HTML前端代码: <?php $this->layout('head'); ?> <?php $this->layout('sidebar'); ?> <m ...
- Kmeans算法--python实现
一:Kmeans算法基本思想: k-means算法是一种很常见的聚类算法,它的基本思想是:通过迭代寻找k个聚类的一种划分方案,使得用这k个聚类的均值来代表相应各类样本时所得的总体误差最小. k-mea ...
- nodejs 循环的陷阱
Node.js 的异步机制由事件和回调函数实现,一开始接触可能会感觉违反常规,但习惯 以后就会发现还是很简单的.然而这之中其实暗藏了不少陷阱,一个很容易遇到的问题就是 循环中的回调函数,初学者经常容易 ...