-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_3_hash_shape.cpp
58 lines (51 loc) · 1.09 KB
/
2_3_hash_shape.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
#include <sstream>
#include <iostream>
#include <iomanip>
/*
Hash shape by using only single cout functions.
*/
using std::cin;
using std::cout;
using std::endl;
using std::setw;
int main()
{
enum lr {LEFT, RIGHT, NEXT};
int hashSizeInCenter = 4;
int repeat = hashSizeInCenter;
int spaceWidth = (hashSizeInCenter-1)*4+1;
int indent = 1;
int pos = LEFT;
int change = 1;
for (int width = 1; width > 0; width += change)
{
pos = LEFT;
while (pos != NEXT)
{
if (pos == LEFT)
{
cout << setw(indent);
}
else {
cout << setw(spaceWidth);
}
for (int hashNum = 0; hashNum < width; hashNum++)
{
cout << "#";
}
pos = ++pos % 3;
}
cout << "\n";
if (width == repeat)
{
width += change;
change *= -1;
repeat = -1;
continue;
}
spaceWidth -= 4*change;
indent += change;
}
cin.get();
return 0;
}