-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGoodsArr.h
72 lines (68 loc) · 1.14 KB
/
GoodsArr.h
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
#ifndef GOODSARR_H
#define GOODSARR_H
#include <QTextStream>
#include <cassert>
class GoodsArr
{
public:
explicit GoodsArr();
GoodsArr(const QString &str);
unsigned& operator[](int i)
{
assert (i<8);
return arr[i];
}
const unsigned& operator[](int i) const
{
assert (i<8);
return arr[i];
}
bool empty() const
{
unsigned sum=0;
for(int i=0; i<8; i++){
sum+=arr[i];
}
return !sum;
}
void set(unsigned d)
{
for(int i=0; i<8; i++)
{
arr[i]=d;
}
}
GoodsArr min(const GoodsArr& other) const
{
GoodsArr result;
for(int i=0; i<8; i++){
result[i]=std::min(arr[i],other.arr[i]);
}
return result;
}
GoodsArr min(const GoodsArr& other, const GoodsArr& sieve) const
{
GoodsArr result;
for(int i=0; i<8; i++){
if(sieve.arr[i])
{
result[i]=std::min(arr[i],other.arr[i]);
}
else {
result[i]=arr[i];
}
}
return result;
}
GoodsArr max(const GoodsArr& other) const
{
GoodsArr result;
for(int i=0; i<8; i++){
result[i]=std::max(arr[i],other.arr[i]);
}
return result;
}
private:
unsigned arr[8];
};
#endif // GOODSARR_H