-
Notifications
You must be signed in to change notification settings - Fork 0
/
Combination.cpp
118 lines (102 loc) · 2.85 KB
/
Combination.cpp
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
114
115
116
117
118
#include "Combination.h"
#include <iostream>
Combination::Combination()
: m_cmb(0)
, m_len(0) {
}
Combination::Combination(const Combination& c)
: m_cmb(new char[c.m_len])
, m_len(c.m_len) {
for (int i = 0; i < m_len; ++i)
m_cmb[i] = c.m_cmb[i];
}
Combination::Combination(int len)
: m_cmb(new char[len])
, m_len(len) {
for (int i = 0; i < m_len; ++i)
m_cmb[i] = 0;
}
Combination::Combination(const char cmb[], int len)
: m_cmb(new char[len])
, m_len(len) {
for (int i = 0; i < m_len; ++i)
m_cmb[i] = cmb[i];
}
Combination::~Combination() {
delete m_cmb;
}
const Combination Combination::operator=(const Combination& c) {
char* tmp = new char[c.m_len];
m_len = c.m_len;
delete m_cmb;
m_cmb = tmp;
for (int i = 0; i < m_len; ++i)
m_cmb[i] = c.m_cmb[i];
return *this;
}
const Combination Combination::operator+(const Combination& c) const {
if (m_len != c.m_len)
std::runtime_error("Combination::operator+. Arguments dimentions are not equal");
Combination tmp(c);
for (int i = 0; i < m_len; ++i)
tmp.m_cmb[i] ^= m_cmb[i];