Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Programming introduction / Solutions Sem. 03 / 15. Bowtie.cpp
blob: e06ab7e91ed0db941e8c51902bd9b5d7ca6c454b (plain) (blame)
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
#include <iostream>

using namespace std;

int main() {
	int n;
	cin >> n;

	char middleSpacer = ' ';
	for(int i = -n + 1; i < n; i++)
	{
		int absI = (i < 0) ? -i : i, diff = n - absI;

		/* Numbers on the left */
		for(int j = 1; j <= diff; j++)
			cout << j << " ";

		/* Spaces/Line in the middle */
		if (i == 0) 
			middleSpacer = '-';

		for(int j = 5 * n - 4 * diff; j > 0; j--)
			cout << middleSpacer;

		if (i == 0)
			middleSpacer = ' ';

		/* Number on the right */
		for(int j = diff; j > 0; j--)
			cout << " " << j;

		cout << endl;
	}
}