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