fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. // Funkcja rekurencyjna rysująca zbiór Cantora
  5. void cantor(int level, std::string line) {
  6. if (level == 0) {
  7. std::cout << line << std::endl;
  8. return;
  9. }
  10.  
  11. // Rysujemy górną część (pełny odcinek)
  12. cantor(level - 1, line);
  13.  
  14. // Rysujemy środkową część z przerwą
  15. std::string newLine;
  16. for (char c : line) {
  17. newLine += (c == '-' ? ' ' : '-'); // zamieniamy środkową część na spacje
  18. }
  19. cantor(level - 1, newLine);
  20. }
  21.  
  22. int main() {
  23. int n = 6; // stopień zbioru Cantora
  24. int width = 1 << n; // szerokość odcinka (2^n)
  25.  
  26. // Tworzymy początkowy odcinek pełny
  27. std::string line(width, '-');
  28.  
  29. // Wywołanie funkcji rekurencyjnej
  30. cantor(n, line);
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
----------------------------------------------------------------
                                                                
                                                                
----------------------------------------------------------------
                                                                
----------------------------------------------------------------
----------------------------------------------------------------
                                                                
                                                                
----------------------------------------------------------------
----------------------------------------------------------------
                                                                
----------------------------------------------------------------
                                                                
                                                                
----------------------------------------------------------------
                                                                
----------------------------------------------------------------
----------------------------------------------------------------
                                                                
----------------------------------------------------------------
                                                                
                                                                
----------------------------------------------------------------
----------------------------------------------------------------
                                                                
                                                                
----------------------------------------------------------------
                                                                
----------------------------------------------------------------
----------------------------------------------------------------
                                                                
                                                                
----------------------------------------------------------------
----------------------------------------------------------------
                                                                
----------------------------------------------------------------
                                                                
                                                                
----------------------------------------------------------------
----------------------------------------------------------------
                                                                
                                                                
----------------------------------------------------------------
                                                                
----------------------------------------------------------------
----------------------------------------------------------------
                                                                
----------------------------------------------------------------
                                                                
                                                                
----------------------------------------------------------------
                                                                
----------------------------------------------------------------
----------------------------------------------------------------
                                                                
                                                                
----------------------------------------------------------------
----------------------------------------------------------------
                                                                
----------------------------------------------------------------
                                                                
                                                                
----------------------------------------------------------------