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();
java如何将click_id转成clickId驼峰的字段 click_like
1、.click()的替代方法 使用.click()无法展开二级菜单,遇到这个问题的时候,不妨可以试试模拟键盘的操作,用.send_keys(Keys.ENTER)可以解决这个问题。from selenium.webdriver.common.keys import Keys
def type_openGoodList(self):
sleep(2)
self.f
java修改文件作者 java如何修改文件名称
Java 实例 - 文件重命名和设置文件只读Java 实例 - 文件重命名以下实例演示了使用 File 类的 oldName.renameTo(newName) 方法来重命名文件。执行以下程序前需要在当前目录下创建测试文件runoob-test.txt。
Main.java 文件
import java.io.File;
import java.io.IOException;
public cla