Skip to content

Commit 7f0b67d

Browse files
committed
Editorial : Plot the pattern
1 parent fe072a8 commit 7f0b67d

File tree

12 files changed

+486
-0
lines changed

12 files changed

+486
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
int main()
4+
{
5+
int n;
6+
cin >> n;
7+
vector<vector<int>> ans;
8+
9+
int cnt = 1;
10+
for (int i = 1; i <= n; i++)
11+
{
12+
vector<int> temp;
13+
for (int j = 0; j < i; j++)
14+
{
15+
temp.push_back(cnt);
16+
cnt++;
17+
}
18+
ans.push_back(temp);
19+
};
20+
for (auto it : ans)
21+
{
22+
for (auto ele : it)
23+
cout << ele << " ";
24+
cout << "\n";
25+
}
26+
for (int i = n - 1; i >= 0; i--)
27+
{
28+
for (int j = ans[i].size() - 1; j >= 0; j--)
29+
{
30+
cout << ans[i][j] << " ";
31+
}
32+
cout << "\n";
33+
}
34+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
n = int(input())
2+
cnt = 1
3+
4+
for i in range(1, n + 1):
5+
for j in range(i):
6+
print(cnt, end=" ")
7+
cnt += 1
8+
print()
9+
10+
start = cnt - 1
11+
for i in range(n, 0, -1):
12+
for j in range(i):
13+
print(start, end=" ")
14+
start -= 1
15+
print()
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int rows;
7+
cin >> rows;
8+
9+
for (int i = 1; i <= rows; i++)
10+
{
11+
for (int j = 2 * rows - i; j > i; j--)
12+
{
13+
cout << " ";
14+
}
15+
16+
for (int j = i; j >= 1; j--)
17+
{
18+
if (j == i || j == 1)
19+
{
20+
cout << "* ";
21+
}
22+
else
23+
{
24+
cout << " ";
25+
}
26+
}
27+
28+
cout << endl;
29+
}
30+
31+
for (int i = rows - 1; i >= 1; i--)
32+
{
33+
for (int j = 2 * rows - i; j > i; j--)
34+
{
35+
cout << " ";
36+
}
37+
38+
for (int j = i; j >= 1; j--)
39+
{
40+
if (j == i || j == 1)
41+
{
42+
cout << "* ";
43+
}
44+
else
45+
{
46+
cout << " ";
47+
}
48+
}
49+
50+
cout << endl;
51+
}
52+
53+
return 0;
54+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
rows = int(input())
2+
3+
for i in range(1, rows + 1):
4+
for j in range(2 * rows - i, i, -1):
5+
print(" ", end="")
6+
7+
for j in range(i, 0, -1):
8+
if j == i or j == 1:
9+
print("* ", end="")
10+
else:
11+
print(" ", end="")
12+
13+
print()
14+
15+
for i in range(rows - 1, 0, -1):
16+
for j in range(2 * rows - i, i, -1):
17+
print(" ", end="")
18+
19+
for j in range(i, 0, -1):
20+
if j == i or j == 1:
21+
print("* ", end="")
22+
else:
23+
print(" ", end="")
24+
25+
print()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
string generate(int cnt, int n)
4+
{
5+
string ans;
6+
if (2 * cnt >= n)
7+
{
8+
for (int i = 0; i < n; i++)
9+
{
10+
ans += '*';
11+
ans += ' ';
12+
}
13+
return ans;
14+
}
15+
else
16+
{
17+
for (int i = 0; i < cnt; i++)
18+
{
19+
ans += '*';
20+
ans += ' ';
21+
}
22+
for (int i = 0; i < n - 2 * cnt; i++)
23+
{
24+
ans += ' ';
25+
ans += ' ';
26+
}
27+
for (int i = 0; i < cnt; i++)
28+
{
29+
ans += '*';
30+
ans += ' ';
31+
}
32+
}
33+
return ans;
34+
}
35+
int main()
36+
{
37+
int n;
38+
cin >> n;
39+
vector<string> v1;
40+
int startvalue = (n / 2) + 1;
41+
for (int i = startvalue; i >= 1; i--)
42+
{
43+
cout << generate(i, n) << "\n";
44+
}
45+
for (int i = 2; i <= startvalue; i++)
46+
{
47+
cout << generate(i, n) << "\n";
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
def generate(cnt, n):
2+
result = ""
3+
4+
if 2 * cnt >= n:
5+
result = "* " * n
6+
else:
7+
result += "* " * cnt
8+
result += " " * (n - 2 * cnt)
9+
result += "* " * cnt
10+
11+
return result
12+
13+
n = int(input())
14+
pattern = []
15+
16+
start_value = (n // 2) + 1
17+
for i in range(start_value, 0, -1):
18+
pattern.append(generate(i, n))
19+
20+
for i in range(2, start_value + 1):
21+
pattern.append(generate(i, n))
22+
23+
for line in pattern:
24+
print(line)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
int main()
4+
{
5+
ios::sync_with_stdio(false);
6+
cin.tie(0);
7+
int n;
8+
cin >> n;
9+
int cnt1 = n / 2;
10+
int cnt2 = n / 2;
11+
int cnt3 = 1;
12+
bool check = false;
13+
for (int i = 0; i < n + 2; i++)
14+
{
15+
cout << '*';
16+
}
17+
cout << endl;
18+
for (int j = 0; j < n; j++)
19+
{
20+
cout << '*';
21+
for (int i = 0; i < n; i++)
22+
{
23+
if (i == cnt1 || i == cnt2)
24+
{
25+
cout << cnt3;
26+
cnt3++;
27+
if (cnt3 == 10)
28+
{
29+
cnt3 = 0;
30+
}
31+
}
32+
else
33+
{
34+
cout << ' ';
35+
}
36+
}
37+
if (check == false)
38+
{
39+
cnt1++;
40+
cnt2--;
41+
if (cnt2 == 0)
42+
{
43+
check = true;
44+
}
45+
}
46+
else
47+
{
48+
cnt1--;
49+
cnt2++;
50+
}
51+
cout << '*' << endl;
52+
}
53+
for (int i = 0; i < n + 2; i++)
54+
{
55+
cout << '*';
56+
}
57+
cout << endl;
58+
return 0;
59+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
n = int(input())
2+
3+
cnt1 = n // 2
4+
cnt2 = n // 2
5+
cnt3 = 1
6+
check = False
7+
8+
print('*' * (n + 2))
9+
10+
for j in range(n):
11+
print('*', end="")
12+
for i in range(n):
13+
if i == cnt1 or i == cnt2:
14+
print(cnt3, end="")
15+
cnt3 += 1
16+
if cnt3 == 10:
17+
cnt3 = 0
18+
else:
19+
print(' ', end="")
20+
21+
if not check:
22+
cnt1 += 1
23+
cnt2 -= 1
24+
if cnt2 == 0:
25+
check = True
26+
else:
27+
cnt1 -= 1
28+
cnt2 += 1
29+
30+
print('*')
31+
32+
print('*' * (n + 2))
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int n;
7+
cin >> n;
8+
vector<vector<char>> vec(2 * n, vector<char>(2 * n, '*'));
9+
int i = 1;
10+
while (i < n)
11+
{
12+
int rs = i, cs = i, re = 2 * n - i, ce = 2 * n - i;
13+
int rowStart = rs, colStart = cs;
14+
while (rs != re)
15+
{
16+
vec[rs][cs] = '#';
17+
vec[rs][ce - 1] = '#';
18+
rs++;
19+
}
20+
rs = rowStart;
21+
while (cs != ce)
22+
{
23+
vec[rs][cs] = '#';
24+
vec[re - 1][cs] = '#';
25+
cs++;
26+
}
27+
i += 2;
28+
}
29+
30+
for (int i = 0; i < 2 * n; i++)
31+
{
32+
for (int j = 0; j < 2 * n; j++)
33+
{
34+
cout << vec[i][j];
35+
}
36+
cout << "\n";
37+
}
38+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
n = int(input())
2+
3+
vec = [['*' for _ in range(2 * n)] for _ in range(2 * n)]
4+
5+
i = 1
6+
while i < n:
7+
rs, cs = i, i
8+
re, ce = 2 * n - i, 2 * n - i
9+
row_start, col_start = rs, cs
10+
11+
while rs != re:
12+
vec[rs][cs] = '#'
13+
vec[rs][ce - 1] = '#'
14+
rs += 1
15+
16+
rs = row_start
17+
while cs != ce:
18+
vec[rs][cs] = '#'
19+
vec[re - 1][cs] = '#'
20+
cs += 1
21+
22+
i += 2
23+
24+
for row in vec:
25+
print("".join(row))

0 commit comments

Comments
 (0)