오늘의 알고리즘
[C++]Inheritance Accessing Inherited Functions(해커랭크 Medium)
하늘하늘 .
2022. 4. 6. 17:37
|
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
#include<iostream>
using namespace std;
class A
{
public:
A(){
callA = 0;
}
private:
int callA;
void inc(){
callA++;
}
protected:
void func(int & a)
{
a = a * 2;
inc();
}
public:
int getA(){
return callA;
}
};
class B
{
public:
B(){
callB = 0;
}
private:
int callB;
void inc(){
callB++;
}
protected:
void func(int & a)
{
a = a * 3;
inc();
}
public:
int getB(){
return callB;
}
};
class C
{
public:
C(){
callC = 0;
}
private:
int callC;
void inc(){
callC++;
}
protected:
void func(int & a)
{
a = a * 5;
inc();
}
public:
int getC(){
return callC;
}
};
class D
: public A, B, C
{
int val;
public:
//Initially val is 1
D()
{
val = 1;
}
//Implement this function
void update_val(int new_val)
{
while (new_val % 2 == 0)
{
A::func(val);
new_val /= 2;
}
while (new_val % 3 == 0)
{
B::func(val);
new_val /= 3;
}
while (new_val %5 == 0)
{
C::func(val);
new_val /= 5;
}
}
//For Checking Purpose
void check(int); //Do not delete this line.
};
|
cs |
영어 해석이 안되서 너무 어려웠다...