|  | 
|  | 1 | +#include <bits/stdc++.h> | 
|  | 2 | +#include <gtest/gtest.h> | 
|  | 3 | +using namespace std; | 
|  | 4 | + | 
|  | 5 | + | 
|  | 6 | +//// START | 
|  | 7 | +/* | 
|  | 8 | +## Complex Number Multiplication | 
|  | 9 | + | 
|  | 10 | +*/ | 
|  | 11 | + | 
|  | 12 | + | 
|  | 13 | +class Num { | 
|  | 14 | +	public: | 
|  | 15 | +	int real; | 
|  | 16 | +	int complex; | 
|  | 17 | +	static	Num fromstr(string num){ | 
|  | 18 | +		int p = 1; | 
|  | 19 | +		for (;p < num.size();p++){ | 
|  | 20 | +			if (num[p] == '+') break; | 
|  | 21 | +		} | 
|  | 22 | +		auto n = Num{}; | 
|  | 23 | +		n.real = stoi(num.substr(0,p)); | 
|  | 24 | +		n.complex = stoi(num.substr(p+1,num.size() - p-2)); | 
|  | 25 | +		return n; | 
|  | 26 | +	} | 
|  | 27 | +	string str(){ | 
|  | 28 | +		string ret; | 
|  | 29 | +		ret += to_string(real); | 
|  | 30 | +		ret += "+"; | 
|  | 31 | +		ret += to_string(complex); | 
|  | 32 | +		ret += "i"; | 
|  | 33 | +		return ret; | 
|  | 34 | +	} | 
|  | 35 | +}; | 
|  | 36 | + | 
|  | 37 | +class Solution { | 
|  | 38 | +	public: | 
|  | 39 | +	string complexNumberMultiply(string num1, string num2) { | 
|  | 40 | +		auto n1 = Num::fromstr(num1); | 
|  | 41 | +		auto n2 = Num::fromstr(num2); | 
|  | 42 | +		auto r = Num{}; | 
|  | 43 | +		r.real = n1.real * n2.real + n1.complex * n2.complex; | 
|  | 44 | +		r.complex = n1.complex*n2.real + n1.real*n2.complex; | 
|  | 45 | +		return r.str(); | 
|  | 46 | +	} | 
|  | 47 | +}; | 
|  | 48 | +//// END | 
|  | 49 | +struct T{ | 
|  | 50 | + | 
|  | 51 | +}; | 
|  | 52 | + | 
|  | 53 | +TEST(Solution,test){ | 
|  | 54 | +	T ts[] = { | 
|  | 55 | +		{ | 
|  | 56 | + | 
|  | 57 | +		}, | 
|  | 58 | +		{ | 
|  | 59 | + | 
|  | 60 | +		}, | 
|  | 61 | + | 
|  | 62 | +	}; | 
|  | 63 | + | 
|  | 64 | + | 
|  | 65 | +	for (T t : ts){ | 
|  | 66 | +		Solution solution; | 
|  | 67 | + | 
|  | 68 | +	} | 
|  | 69 | +} | 
|  | 70 | + | 
|  | 71 | +int main() { | 
|  | 72 | +	testing::InitGoogleTest(); | 
|  | 73 | + | 
|  | 74 | +	return RUN_ALL_TESTS(); | 
|  | 75 | +} | 
|  | 76 | + | 
|  | 77 | + | 
0 commit comments