C++ | Leetcode C++题解之第537题复数乘法
题目:
题解:
class Solution {
public:
string complexNumberMultiply(string num1, string num2) {
regex re("\\+|i");
vector<string> complex1(sregex_token_iterator(num1.begin(), num1.end(), re, -1), std::sregex_token_iterator());
vector<string> complex2(sregex_token_iterator(num2.begin(), num2.end(), re, -1), std::sregex_token_iterator());
int real1 = stoi(complex1[0]);
int imag1 = stoi(complex1[1]);
int real2 = stoi(complex2[0]);
int imag2 = stoi(complex2[1]);
return to_string(real1 * real2 - imag1 * imag2) + "+" + to_string(real1 * imag2 + imag1 * real2) + "i";
}
};
原文地址:https://blog.csdn.net/Ddddddd_158/article/details/143474482
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!