-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path17.12.cpp
62 lines (55 loc) · 1.51 KB
/
17.12.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
#include <bitset>
#include <cstddef>
#include <string>
#include <utility>
#include <iostream>
using std::bitset;
using std::size_t;
using std::string;
using std::cout;
using std::endl;
template <size_t N> class Test;
template <size_t N> std::ostream &operator<<(std::ostream &, const Test<N> &);
template <size_t N>
class Test {
friend std::ostream &operator<< <N>(std::ostream &, const Test<N> &);
public:
Test() = default;
explicit Test(const string &s, size_t pos = 0, size_t m = string::npos,
char zero = '0', char one = '1') : questions(s, pos, m, zero, one) {}
explicit Test(string &&s, size_t pos = 0, size_t m = string::npos,
char zero = '0', char one = '1') noexcept : questions(std::move(s), pos, m, zero, one) {}
explicit Test(const char *cp, size_t m = size_t(-1),
char zero = '0', char one = '1') : questions(cp, m, zero, one) {}
Test(unsigned long long u) : questions(u) {}
void updateBit(size_t n, bool b) {
questions.set(n, b);
}
private:
bitset<N> questions;
};
template <size_t N>
std::ostream &operator<<(std::ostream &os, const Test<N> &t) {
return os << t.questions;
}
int main() {
Test<8> bseq;
cout << bseq << endl;
for (size_t i = 0; i != 8; ++i) {
bseq.updateBit(i, true);
cout << bseq << endl;
}
for (size_t i = 8; i != 0; --i) {
bseq.updateBit(i - 1, false);
cout << bseq << endl;
}
for (size_t i = 8; i != 0; --i) {
bseq.updateBit(i - 1, true);
cout << bseq << endl;
}
for (size_t i = 0; i != 8; ++i) {
bseq.updateBit(i, false);
cout << bseq << endl;
}
return 0;
}