-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1999 S3.cpp
94 lines (55 loc) · 2.25 KB
/
1999 S3.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
/*
1999 S3 - Divided Fractals
Difficulty: Easy
For this problem, since there will be at max 5 iterations. You can just generate the actual fractal using recursion and print out the required rows and columns.
Watch out for extra white space and missing new lines that might cause presentation error.
*/
#include <iostream>
#include <vector>
std::vector<std::vector<char>> fractal {{'*'}}; //Base is just a 3^0 * 3^0 grid.
//What this does is create the next iteration.
void iterate(){
int l = fractal.size(); //Keep track of original fractal size, updated fractal will be 3 times larger
std::vector<std::vector<char>> fractal_copy = fractal; //Make a copy of the fractal since the bigger fractal is made up of 8 copies of the original
fractal.clear(); //Clear the original fractal
fractal.resize(l * 3, std::vector<char> (l * 3)); //Resize it accordingly
//Fill the new fractal with 9 copies of the original
for (int i = 0; i < l * 3; i++){
for (int j = 0; j < l * 3; j++){
fractal[i][j] = fractal_copy[i % l][j % l];
}
}
//Delete the middle portion
for (int i = l; i < l * 2; i++){
for (int j = l; j < l * 2; j++){
fractal[i][j] = ' ';
}
}
}
int main(){
int d;
std::cin >> d;
//For each case
for (int i = 0; i < d; i++){
int n; std::cin >> n;
//Iterate however many times needed
for (int j = 0; j < n; j++){
iterate();
}
int b, t, l, r;
std::cin >> b >> t >> l >> r;
//Print out rows and columns, remember that rows are inputted from bottom up
for (int j = fractal.size() - t; j < fractal.size() - b + 1; j++){
//Stop before r - 1, aka the last element in the row because we don't want to output an additonal space
for (int c = l - 1; c < r - 1; c++){
std::cout << fractal[j][c] << ' ';
}
std::cout << fractal[j][r - 1]; //Output value without the extra space
std::cout << '\n'; //Newline
}
std::cout << '\n'; //Output a new line after each case
fractal.clear(); //Clear the fractal
fractal = {{'*'}}; //Reset it for the next case
}
return 0;
}