leetcode 537. Complex Number Multiplication C++中的stringstream真的很好用
来源:互联网 发布:秋风印花分色软件 编辑:程序博客网 时间:2024/06/05 19:23
Given two strings representing two complex numbers.
You need to return a string representing their multiplication. Note i2 = -1 according to the definition.
Example 1:
Input: “1+1i”, “1+1i”
Output: “0+2i”
Explanation: (1 + i) * (1 + i) = 1 + i2 + 2 * i = 2i, and you need convert it to the form of 0+2i.
Example 2:
Input: “1+-1i”, “1+-1i”
Output: “0+-2i”
Explanation: (1 - i) * (1 - i) = 1 + i2 - 2 * i = -2i, and you need convert it to the form of 0+-2i.
Note:
The input strings will not have extra blank.
The input strings will be given in the form of a+bi, where the integer a and b will both belong to the range of [-100, 100]. And the output should be also in this form.
本题意很简单,就是计算复数的乘法,
这道题最大的启发就是C++的stringstream真的很好用
建议和这一道题leetcode 539. Minimum Time Difference C++中的stringstream真的很好用 一起学习
代码如下:
#include <iostream>#include <vector>#include <map>#include <set>#include <queue>#include <stack>#include <string>#include <climits>#include <algorithm>#include <sstream>#include <functional>#include <bitset>#include <numeric>#include <cmath>using namespace std;class Solution{public: string complexNumberMultiply(string a, string b) { int ra, ia, rb, ib; char buff; stringstream aa(a), bb(b), ans; aa >> ra >> buff >> ia >> buff; bb >> rb >> buff >> ib >> buff; ans << ra*rb - ia*ib << "+" << ra*ib + rb*ia << "i"; return ans.str(); }};
- leetcode 537. Complex Number Multiplication C++中的stringstream真的很好用
- [Leetcode] #537 Complex Number Multiplication(stringstream)
- Leetcode-537. Complex Number Multiplication
- leetcode 537. Complex Number Multiplication
- LeetCode 537. Complex Number Multiplication
- Leetcode 537. Complex Number Multiplication
- leetcode 537. Complex Number Multiplication
- LeetCode | 537. Complex Number Multiplication
- LeetCode:537. Complex Number Multiplication
- LeetCode----537. Complex Number Multiplication
- [leetcode]537. Complex Number Multiplication
- LeetCode-537. Complex Number Multiplication
- [LeetCode]537. Complex Number Multiplication
- [leetcode]: 537. Complex Number Multiplication
- 【LeetCode】537. Complex Number Multiplication
- LeetCode 537. Complex Number Multiplication
- 537. Complex Number Multiplication(C++)
- 【leetcode】537. Complex Number Multiplication(Python & C++)
- 23. Merge k Sorted Lists
- 函数
- Linux Shell是什么?
- 初遇 Source Maps
- UCOM使用手册在线版
- leetcode 537. Complex Number Multiplication C++中的stringstream真的很好用
- Intellij IDEA使用(九)—— 使用Intellij IDEA创建JavaWeb项目并配置jar包
- 最近几个月总结(17年12月)
- Linux shell 中的那些你值得一试的小把戏
- 实验2.1:交换机VLAN配置
- spark参数调优
- 双忆大脑
- spring cloud 报[Circular view path [refundbbb]: would dispatch back to the current handler URL [/refu
- Python.pygame 开篇