#include <iostream> #include <string> // Funkcja rekurencyjna rysująca zbiór Cantora void cantor(int level, std::string line) { if (level == 0) { std::cout << line << std::endl; return; } // Rysujemy górną część (pełny odcinek) cantor(level - 1, line); // Rysujemy środkową część z przerwą std::string newLine; for (char c : line) { newLine += (c == '-' ? ' ' : '-'); // zamieniamy środkową część na spacje } cantor(level - 1, newLine); } int main() { int n = 6; // stopień zbioru Cantora int width = 1 << n; // szerokość odcinka (2^n) // Tworzymy początkowy odcinek pełny std::string line(width, '-'); // Wywołanie funkcji rekurencyjnej cantor(n, line); return 0; }
Standard input is empty
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------