aboutsummaryrefslogtreecommitdiff
path: root/week10/ex3.cpp
blob: 1edf55d385e3cefa1951c4e89a972c76f0eda463 (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
#include <iostream>

void printCharNTimes(int n, char c) {
	for (int i = 0; i < n; i++) {
		std::cout << c;
	}
}

void hourglass(int lines, int whitespaces, int nonwhitespace) {
	if (lines == 0) return;

	printCharNTimes(whitespaces, ' ');
	printCharNTimes(nonwhitespace, '+');
	std::cout << std::endl;

	hourglass(lines - 1, whitespaces + 1, nonwhitespace - 2);

	printCharNTimes(whitespaces, ' ');
	printCharNTimes(nonwhitespace, '#');
	std::cout << std::endl;
}

int main() {
	int N;
	std::cin >> N;
	hourglass(N, 0, 2*N - 1);
}