字符串537. 复数乘法
Posted ocpc
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了字符串537. 复数乘法相关的知识,希望对你有一定的参考价值。
题目:
解答:
1 class Solution { 2 public: 3 string complexNumberMultiply(string a, string b) 4 { 5 int a1 = stoi(a); 6 int b1 = stoi(b); 7 8 int i = 0; 9 int j = 0; 10 11 while (a[i] != ‘+‘) 12 { 13 i++; 14 } 15 while (b[j] != ‘+‘) 16 { 17 j++; 18 } 19 20 a = a.substr(i + 1); 21 b = b.substr(j + 1); 22 int a2 = stoi(a); 23 int b2 = stoi(b); 24 25 string res1 = to_string(a1 * b1 - a2 * b2); 26 string res2 = to_string(a1 * b2 + a2 * b1); 27 28 return res1 + "+" + res2 + "i"; 29 } 30 };
以上是关于字符串537. 复数乘法的主要内容,如果未能解决你的问题,请参考以下文章