标签:res substr pre inf image 乘法 lex nbsp img
题目:
解答:
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 };
标签:res substr pre inf image 乘法 lex nbsp img
原文地址:https://www.cnblogs.com/ocpc/p/12826049.html